diff options
author | Alain Frisch <alain@frisch.fr> | 2018-04-30 12:39:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-30 12:39:12 +0200 |
commit | 672e615b8152138ac1a921d7bf5a6471dc21d8a4 (patch) | |
tree | 1399fb5dbe562b995d78e0a83591b84f4c118ef9 | |
parent | bcfa95848bc28a67513b2136e830ae573d238e4b (diff) | |
parent | 9273bab69e3c2cbd45595797cf231339d92d6fe2 (diff) | |
download | ocaml-fix_large_file_lseek_windows.tar.gz |
Merge branch 'trunk' into fix_large_file_lseek_windowsfix_large_file_lseek_windows
185 files changed, 2336 insertions, 1220 deletions
diff --git a/.gitignore b/.gitignore index 937be67c2f..e6a8ba84a3 100644 --- a/.gitignore +++ b/.gitignore @@ -248,75 +248,13 @@ _ocamltestd /testsuite/_retries -/testsuite/tests/asmgen/codegen -/testsuite/tests/asmgen/parsecmm.ml -/testsuite/tests/asmgen/parsecmm.mli -/testsuite/tests/asmgen/lexcmm.ml -/testsuite/tests/asmgen/*.s -/testsuite/tests/asmgen/*.out.manifest - - -/testsuite/tests/embedded/caml - -/testsuite/tests/lib-dynlink-native/mypack.pack.s -/testsuite/tests/lib-dynlink-native/mypack.pack.asm -/testsuite/tests/lib-dynlink-native/result -/testsuite/tests/lib-dynlink-native/main -/testsuite/tests/lib-dynlink-native/marshal.data -/testsuite/tests/lib-dynlink-native/caml - -/testsuite/tests/lib-scanf/tscanf_data - -/testsuite/tests/lib-threads/*.byt - -/testsuite/tests/output_obj/*.bc.c -/testsuite/tests/output_obj/*_stub -/testsuite/tests/output_obj/*_stub - -/testsuite/tests/runtime-errors/*.bytecode - -/testsuite/tests/self-contained-toplevel/cached_cmi.ml - -/testsuite/tests/tool-ocamldep-modalias/*.byt* -/testsuite/tests/tool-ocamldep-modalias/*.opt* -/testsuite/tests/tool-ocamldep-modalias/depend.mk -/testsuite/tests/tool-ocamldep-modalias/depend.mk2 -/testsuite/tests/tool-ocamldep-modalias/depend.mod -/testsuite/tests/tool-ocamldep-modalias/depend.mod2 -/testsuite/tests/tool-ocamldep-modalias/depend.mod3 - -/testsuite/tests/tool-ocamldoc/*.html -/testsuite/tests/tool-ocamldoc/*.sty -/testsuite/tests/tool-ocamldoc/*.css - -/testsuite/tests/tool-ocamldoc-2/ocamldoc.sty - -/testsuite/tests/tool-ocamldoc-html/*.html -/testsuite/tests/tool-ocamldoc-html/style.css - -/testsuite/tests/tool-ocamldoc-man/*.3o - -/testsuite/tests/tool-ocamldoc-open/alias.odoc -/testsuite/tests/tool-ocamldoc-open/inner.odoc -/testsuite/tests/tool-ocamldoc-open/main.odoc -/testsuite/tests/tool-ocamldoc-open/ocamldoc.sty - -/testsuite/tests/tool-lexyacc/scanner.ml -/testsuite/tests/tool-lexyacc/grammar.mli -/testsuite/tests/tool-lexyacc/grammar.ml - -/testsuite/tests/typing-unboxed-types/false.flat-float -/testsuite/tests/typing-unboxed-types/true.flat-float -/testsuite/tests/typing-unboxed-types/test.ml.reference - -/testsuite/tests/unboxed-primitive-args/main.ml -/testsuite/tests/unboxed-primitive-args/stubs.c - -/testsuite/tests/unwind/unwind_test - /testsuite/tests/win-unicode/symlink_tests.precheck +/testsuite/tools/codegen /testsuite/tools/expect_test +/testsuite/tools/lexcmm.ml +/testsuite/tools/parsecmm.ml +/testsuite/tools/parsecmm.mli /tools/ocamldep /tools/ocamldep.opt @@ -9,16 +9,26 @@ Working version ### Standard library: +- GPR#1731: Format, use raise_notrace to preserve backtraces + (Frédéric Bour, report by Jules Villard, review by Gabriel Scherer) + ### Other libraries: ### Compiler user-interface and warnings: + -GPR#1733: change the perspective of the unexpected existential error message + (Florian Angeletti, review by Gabriel Scherer and Jeremy Yallop) + ### Code generation and optimizations: ### Runtime system: ### Tools: +- GPR#1711: the new 'open' flag in OCAMLRUNPARAM takes a comma-separated list of + modules to open as if they had been passed via the command line -open flag. + (Nicolás Ojeda Bär, review by Mark Shinwell) + ### Manual and documentation: ### Compiler distribution build system: @@ -34,6 +44,9 @@ Working version - GPR#1719: fix Pervasives.LargeFile functions under Windows (Alain Frisch) +- GPR#1739: ensure ocamltest waits for child processes to terminate on Windows + (David Allsopp, review by Sébastien Hinderer) + OCaml 4.07 ---------- @@ -52,6 +65,9 @@ OCaml 4.07 - GPR#1546: Allow empty variants (Runhang Li, review by Gabriel Radanne and Jacques Garrigue) +- GRP#1705: Allow @@attributes on exceptions + (Hugo Heuzard, review by Gabriel Radanne) + ### Type system: - MPR#7767, GPR#1712: restore legacy treatment of partially-applied @@ -312,6 +328,10 @@ OCaml 4.07 - GPR#1695: add the -null-crc command-line option to ocamlobjinfo. (Sébastien Hinderer, review by David Allsopp and Gabriel Scherer) +- GPR#1710: ocamldoc, improve the 'man' rendering of subscripts and + superscripts. + (Gabriel Scherer) + ### Manual and documentation: - MPR#7613: minor reword of the "refutation cases" paragraph @@ -334,6 +354,9 @@ OCaml 4.07 - GPR#1647: manual, subsection on record and variant disambiguation (Florian Angeletti, review by Alain Frisch and Gabriel Scherer) +- GPR#1741: manual, improve typesetting and legibility in HTML output + (steinuil, review by Gabriel Scherer) + ### Compiler distribution build system - MPR#5219, GPR#1680: use 'install' instead of 'cp' in install scripts @@ -471,6 +494,11 @@ OCaml 4.07 - MPR#7751, GPR#1657: The toplevel prints some concrete types as abstract (Jacques Garrigue, report by Matej Kosik) +- MPR#7765, GPR#1718: When unmarshaling bigarrays, protect against integer + overflows in size computations + (Xavier Leroy, report by Maximilian Tschirschnitz, + review by Gabriel Scherer) + - PR#7760, GPR#1713: Exact selection of lexing engine, that is correct "Segfault in ocamllex-generated code using 'shortest'" (Luc Maranget, Frédéric Bour, report by Stephen Dolan, @@ -499,6 +527,9 @@ OCaml 4.07 disambiguation (Thomas Refis, review by Leo White) +- GPR#1722: Scrape types in Typeopt.maybe_pointer + (Leo White, review by Thomas Refis) + OCaml 4.06.1 (16 Feb 2018): --------------------------- diff --git a/bytecomp/translmod.ml b/bytecomp/translmod.ml index 4644feac7a..fe9751ade6 100644 --- a/bytecomp/translmod.ml +++ b/bytecomp/translmod.ml @@ -552,13 +552,13 @@ and transl_structure loc fields cc rootpath final_env = function in transl_type_extension item.str_env rootpath tyext body, size | Tstr_exception ext -> - let id = ext.ext_id in + let id = ext.tyexn_constructor.ext_id in let path = field_path rootpath id in let body, size = transl_structure loc (id :: fields) cc rootpath final_env rem in Llet(Strict, Pgenval, id, - transl_extension_constructor item.str_env path ext, body), + transl_extension_constructor item.str_env path ext.tyexn_constructor, body), size | Tstr_module mb -> let id = mb.mb_id in @@ -727,7 +727,7 @@ let rec defined_idents = function | Tstr_typext tyext -> List.map (fun ext -> ext.ext_id) tyext.tyext_constructors @ defined_idents rem - | Tstr_exception ext -> ext.ext_id :: defined_idents rem + | Tstr_exception ext -> ext.tyexn_constructor.ext_id :: defined_idents rem | Tstr_module mb -> mb.mb_id :: defined_idents rem | Tstr_recmodule decls -> List.map (fun mb -> mb.mb_id) decls @ defined_idents rem @@ -782,7 +782,7 @@ and all_idents = function | Tstr_typext tyext -> List.map (fun ext -> ext.ext_id) tyext.tyext_constructors @ all_idents rem - | Tstr_exception ext -> ext.ext_id :: all_idents rem + | Tstr_exception ext -> ext.tyexn_constructor.ext_id :: all_idents rem | Tstr_recmodule decls -> List.map (fun mb -> mb.mb_id) decls @ all_idents rem | Tstr_modtype _ -> all_idents rem @@ -870,11 +870,11 @@ let transl_store_structure glob map prims str = Lsequence(Lambda.subst subst lam, transl_store rootpath (add_idents false ids subst) rem) | Tstr_exception ext -> - let id = ext.ext_id in + let id = ext.tyexn_constructor.ext_id in let path = field_path rootpath id in - let lam = transl_extension_constructor item.str_env path ext in + let lam = transl_extension_constructor item.str_env path ext.tyexn_constructor in Lsequence(Llet(Strict, Pgenval, id, Lambda.subst subst lam, - store_ident ext.ext_loc id), + store_ident ext.tyexn_constructor.ext_loc id), transl_store rootpath (add_ident false id subst) rem) | Tstr_module{mb_id=id;mb_loc=loc; mb_expr={mod_desc = Tmod_structure str} as mexp; @@ -1196,9 +1196,9 @@ let transl_toplevel_item item = transl_type_extension item.str_env None tyext (make_sequence toploop_setvalue_id idents) | Tstr_exception ext -> - set_toplevel_unique_name ext.ext_id; - toploop_setvalue ext.ext_id - (transl_extension_constructor item.str_env None ext) + set_toplevel_unique_name ext.tyexn_constructor.ext_id; + toploop_setvalue ext.tyexn_constructor.ext_id + (transl_extension_constructor item.str_env None ext.tyexn_constructor) | Tstr_module {mb_id=id; mb_expr=modl} -> (* we need to use the unique name for the module because of issues with "open" (PR#1672) *) diff --git a/byterun/bigarray.c b/byterun/bigarray.c index cb91730172..3e376799a5 100644 --- a/byterun/bigarray.c +++ b/byterun/bigarray.c @@ -439,22 +439,31 @@ static void caml_ba_deserialize_longarray(void * dest, intnat num_elts) CAMLexport uintnat caml_ba_deserialize(void * dst) { struct caml_ba_array * b = dst; - int i, elt_size; - uintnat num_elts; + int i; + uintnat num_elts, size; /* Read back header information */ b->num_dims = caml_deserialize_uint_4(); + if (b->num_dims < 0 || b->num_dims > CAML_BA_MAX_NUM_DIMS) + caml_deserialize_error("input_value: wrong number of bigarray dimensions"); b->flags = caml_deserialize_uint_4() | CAML_BA_MANAGED; b->proxy = NULL; for (i = 0; i < b->num_dims; i++) b->dim[i] = caml_deserialize_uint_4(); - /* Compute total number of elements */ - num_elts = caml_ba_num_elts(b); - /* Determine element size in bytes */ + /* Compute total number of elements. Watch out for overflows (MPR#7765). */ + num_elts = 1; + for (i = 0; i < b->num_dims; i++) { + if (caml_umul_overflow(num_elts, b->dim[i], &num_elts)) + caml_deserialize_error("input_value: size overflow for bigarray"); + } + /* Determine array size in bytes. Watch out for overflows (MPR#7765). */ if ((b->flags & CAML_BA_KIND_MASK) > CAML_BA_CHAR) caml_deserialize_error("input_value: bad bigarray kind"); - elt_size = caml_ba_element_size[b->flags & CAML_BA_KIND_MASK]; + if (caml_umul_overflow(num_elts, + caml_ba_element_size[b->flags & CAML_BA_KIND_MASK], + &size)) + caml_deserialize_error("input_value: size overflow for bigarray"); /* Allocate room for data */ - b->data = malloc(elt_size * num_elts); + b->data = malloc(size); if (b->data == NULL) caml_deserialize_error("input_value: out of memory for bigarray"); /* Read data */ diff --git a/driver/compenv.ml b/driver/compenv.ml index 2909d67e7d..15a636a466 100644 --- a/driver/compenv.ml +++ b/driver/compenv.ml @@ -48,7 +48,6 @@ let default_output = function | Some s -> s | None -> Config.default_executable_name -let implicit_modules = ref [] let first_include_dirs = ref [] let last_include_dirs = ref [] let first_ccopts = ref [] @@ -236,6 +235,7 @@ let read_one_param ppf position name v = | "pp" -> preprocessor := Some v | "runtime-variant" -> runtime_variant := v + | "open" -> open_modules := List.rev_append (String.split_on_char ',' v) !open_modules | "cc" -> c_compiler := Some v | "clambda-checks" -> set "clambda-checks" [ clambda_checks ] v diff --git a/driver/compenv.mli b/driver/compenv.mli index 0ee9871a6c..d802bb079c 100644 --- a/driver/compenv.mli +++ b/driver/compenv.mli @@ -28,7 +28,6 @@ val first_ccopts : string list ref val first_ppx : string list ref val first_include_dirs : string list ref val last_include_dirs : string list ref -val implicit_modules : string list ref (* function to call on plugin=XXX *) val load_plugin : (string -> unit) ref diff --git a/driver/compmisc.ml b/driver/compmisc.ml index b1bed14b54..9177076ac1 100644 --- a/driver/compmisc.ml +++ b/driver/compmisc.ml @@ -55,7 +55,7 @@ let initial_env () = ~loc:(Location.in_file "command line") ~safe_string:(Config.safe_string || not !Clflags.unsafe_string) ~initially_opened_module - ~open_implicit_modules:(!implicit_modules @ List.rev !Clflags.open_modules) + ~open_implicit_modules:(List.rev !Clflags.open_modules) let read_color_env ppf = try diff --git a/manual/manual/Makefile b/manual/manual/Makefile index 06e2fb086f..ab3d9f19a3 100644 --- a/manual/manual/Makefile +++ b/manual/manual/Makefile @@ -13,10 +13,11 @@ SRC = $(abspath ../../) export LD_LIBRARY_PATH ?= $(SRC)/otherlibs/unix/:$(SRC)/otherlibs/str/ export DYLD_LIBRARY_PATH ?= $(SRC)/otherlibs/unix/:$(SRC)/otherlibs/str/ +SET_LD_PATH=CAML_LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) OCAMLDOC=$(if $(wildcard $(SRC)/ocamldoc/ocamldoc.opt),\ $(SRC)/ocamldoc/ocamldoc.opt,\ - $(SRC)/byterun/ocamlrun $(SRC)/ocamldoc/ocamldoc)\ + $(SET_LD_PATH) $(SRC)/byterun/ocamlrun $(SRC)/ocamldoc/ocamldoc)\ -hide Pervasives -nostdlib -initially-opened-module Pervasives manual: files @@ -43,7 +44,7 @@ index:: # Copy and unprefix the standard library when needed include $(SRC)/ocamldoc/Makefile.unprefix -html: files $(STDLIB_CMIS) +html: files cd htmlman; \ mkdir -p libref ; \ $(OCAMLDOC) -colorize-code -sort -html \ @@ -76,7 +77,8 @@ etex-files: $(FILES) cd cmds; $(MAKE) etex-files RELEASEDIR=$(SRC) cd tutorials; $(MAKE) etex-files RELEASEDIR=$(SRC) -files: $(FILES) +files: $(FILES) $(STDLIB_MLIS) + $(MAKE) unprefix_stdlib_for_ocamldoc cd refman; $(MAKE) all RELEASEDIR=$(SRC) cd library; $(MAKE) all RELEASEDIR=$(SRC) cd cmds; $(MAKE) all RELEASEDIR=$(SRC) @@ -130,7 +132,7 @@ warnings-help.etex: $(SRC)/utils/warnings.ml $(SRC)/ocamlc echo "% are inserted through the Makefile, which should be updated";\ echo "% when a new warning is documented.";\ echo "%";\ - $(SRC)/boot/ocamlrun $(SRC)/ocamlc -warn-help \ + $(SET_LD_PATH) $(SRC)/boot/ocamlrun $(SRC)/ocamlc -warn-help \ | sed -e 's/^ *\([0-9A-Z][0-9]*\)\(.*\)/\\item[\1] \2/'\ ) >$@ # sed --inplace is not portable, emulate diff --git a/manual/manual/cmds/Makefile b/manual/manual/cmds/Makefile index 80e2e803dc..6437ae2ca3 100644 --- a/manual/manual/cmds/Makefile +++ b/manual/manual/cmds/Makefile @@ -6,7 +6,9 @@ FILES=comp.tex top.tex runtime.tex native.tex lexyacc.tex intf-c.tex \ TOPDIR=../../.. include $(TOPDIR)/Makefile.tools -TRANSF=$(OCAMLRUN) ../../tools/transf +LD_PATH="$(TOPDIR)/otherlibs/str:$(TOPDIR)/otherlibs/unix" + +TRANSF=$(SET_LD_PATH) $(OCAMLRUN) ../../tools/transf TEXQUOTE=../../tools/texquote2 FORMAT=../../tools/format-intf diff --git a/manual/manual/library/Makefile b/manual/manual/library/Makefile index 469ae4569a..d085f504f4 100644 --- a/manual/manual/library/Makefile +++ b/manual/manual/library/Makefile @@ -31,6 +31,11 @@ BLURB=core.tex builtin.tex stdlib.tex compilerlibs.tex \ FILES=$(BLURB) $(INTF) +SRC=../../.. + +LD_PATH := $(SRC)/otherlibs/unix/:$(SRC)/otherlibs/str/ +SET_LD_PATH=CAML_LD_LIBRARY_PATH=$(LD_PATH) + FORMAT=../../tools/format-intf TEXQUOTE=../../tools/texquote2 @@ -43,16 +48,16 @@ libs: $(FILES) OCAMLDOC=$(if $(wildcard $(CSLDIR)/ocamldoc/ocamldoc.opt),\ $(CSLDIR)/ocamldoc/ocamldoc.opt,\ - $(CSLDIR)/byterun/ocamlrun $(CSLDIR)/ocamldoc/ocamldoc) \ + $(SET_LD_PATH) $(CSLDIR)/byterun/ocamlrun $(CSLDIR)/ocamldoc/ocamldoc) \ -nostdlib -initially-opened-module Pervasives # Copy and unprefix the standard library when needed -SRC=../../.. include $(SRC)/ocamldoc/Makefile.unprefix + $(INTF): interfaces interfaces: $(STDLIB_CMIS) - $(OCAMLDOC) -latex \ + $(OCAMLDOC) -latex \ -I $(STDLIB_UNPREFIXED) \ $(STDLIB_MLIS) \ -sepfiles \ diff --git a/manual/manual/macros.hva b/manual/manual/macros.hva index 99f4b4ffb8..0c1fe189ac 100644 --- a/manual/manual/macros.hva +++ b/manual/manual/macros.hva @@ -6,6 +6,16 @@ \newstyle{a:visited}{color:\visited@color;text-decoration:underline;} \newstyle{a:hover}{color:black;text-decoration:none;background-color:\hover@color} +% Compact layout +\newstyle{body}{max-width:800px} +\newstyle{@media (min-width:900px)}{body\{margin-left:50px\}} +\newstyle{@media (min-width:1000px)}{body\{margin-left:100px\}} +\newstyle{pre}{overflow-y:auto} + +% More spacing between lines and inside tables +\newstyle{p}{line-height:1.3em} +\newstyle{.cellpadding1 tr td}{padding:1px 4px} + %Styles for caml-example and friends \newstyle{div.caml-output}{color:maroon;} \newstyle{div.caml-example pre}{margin:2ex 0px;} diff --git a/manual/manual/refman/Makefile b/manual/manual/refman/Makefile index 2332c82206..61883ae544 100644 --- a/manual/manual/refman/Makefile +++ b/manual/manual/refman/Makefile @@ -6,9 +6,11 @@ TOPDIR=../../.. include $(TOPDIR)/Makefile.tools -CAMLLATEX= $(OCAMLRUN) ../../tools/caml-tex2 -caml "TERM=norepeat $(OCAML)" \ --n 80 -v false -TRANSF=../../tools/transf +LD_PATH="$(TOPDIR)/otherlibs/str:$(TOPDIR)/otherlibs/unix" + +CAMLLATEX=$(SET_LD_PATH) $(OCAMLRUN) ../../tools/caml-tex2 \ + -caml "TERM=norepeat $(OCAML)" -n 80 -v false +TRANSF=$(SET_LD_PATH) $(OCAMLRUN) ../../tools/transf TEXQUOTE=../../tools/texquote2 ALLFILES=$(FILES) @@ -25,17 +27,17 @@ clean: exten.tex:exten.etex @$(CAMLLATEX) -o $*.caml_tex_error.tex $*.etex \ && mv $*.caml_tex_error.tex $*.gen.tex \ - && $(OCAMLRUN) $(TRANSF) < $*.gen.tex > $*.transf_error.tex \ + && $(TRANSF) < $*.gen.tex > $*.transf_error.tex \ && mv $*.transf_error.tex $*.gen.tex\ && $(TEXQUOTE) < $*.gen.tex > $*.texquote_error.tex\ && mv $*.texquote_error.tex $*.tex\ || printf "Failure when generating %s\n" $*.tex .etex.tex: - @$(OCAMLRUN) $(TRANSF) < $*.etex > $*.transf_error.tex \ + @$(TRANSF) < $*.etex > $*.transf_error.tex \ && mv $*.transf_error.tex $*.gen.tex\ && $(TEXQUOTE) < $*.gen.tex > $*.texquote_error.tex\ && mv $*.texquote_error.tex $*.tex\ || printf "Failure when generating %s\n" $*.tex -$(ALLFILES): $(TRANSF) $(TEXQUOTE) +$(ALLFILES): ../../tools/transf $(TEXQUOTE) diff --git a/manual/manual/refman/exten.etex b/manual/manual/refman/exten.etex index c42934935d..16dbb65cb6 100644 --- a/manual/manual/refman/exten.etex +++ b/manual/manual/refman/exten.etex @@ -2094,7 +2094,7 @@ range @["g".."z"||"G".."Z"]@ are extension-only literals. ; \end{syntax} -The arguments of a sum-type constructors can now be defined using the +The arguments of sum-type constructors can now be defined using the same syntax as records. Mutable and polymorphic fields are allowed. GADT syntax is supported. Attributes can be specified on individual fields. diff --git a/manual/manual/tutorials/Makefile b/manual/manual/tutorials/Makefile index a37132d3a0..b454374d59 100644 --- a/manual/manual/tutorials/Makefile +++ b/manual/manual/tutorials/Makefile @@ -4,7 +4,9 @@ advexamples.tex polymorphism.tex TOPDIR=../../.. include $(TOPDIR)/Makefile.tools -CAMLLATEX= $(OCAMLRUN) ../../tools/caml-tex2 +LD_PATH="$(TOPDIR)/otherlibs/str:$(TOPDIR)/otherlibs/unix" + +CAMLLATEX=$(SET_LD_PATH) $(OCAMLRUN) ../../tools/caml-tex2 TEXQUOTE=../../tools/texquote2 ALLFILES=$(FILES) @@ -26,4 +28,4 @@ clean: && mv $*.texquote_error.tex $*.tex\ || printf "Failure when generating %s\n" $*.tex -$(ALLFILES): $(CAMLLATEX) $(TEXQUOTE) +$(ALLFILES): ../../tools/caml-tex2 $(TEXQUOTE) diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile index afab6eaba8..2fe3c698dd 100644 --- a/ocamldoc/Makefile +++ b/ocamldoc/Makefile @@ -224,10 +224,10 @@ $(OCAMLDOC_LIBCMXA): $(LIBCMXFILES) $(OCAMLOPT) -a -o $@ $(LINKFLAGS) $^ .PHONY: manpages -manpages: stdlib_man/Stdlib.3o +manpages: stdlib_man/Pervasives.3o .PHONY: html_doc -html_doc: stdlib_html/Stdlib.html +html_doc: stdlib_html/Pervasives.html .PHONY: dot dot: ocamldoc.dot @@ -273,10 +273,10 @@ odoc_see_lexer.ml: odoc_see_lexer.mll $(OCAMLLEX) $< .mly.ml: - $(OCAMLYACC) -v $< + $(OCAMLYACC) --strict -v $< .mly.mli: - $(OCAMLYACC) -v $< + $(OCAMLYACC) --strict -v $< # Installation targets ###################### @@ -388,13 +388,15 @@ test_texi: SRC=$(ROOTDIR) include Makefile.unprefix -stdlib_man/Stdlib.3o: $(OCAMLDOC) $(STDLIB_MLIS) $(STDLIB_CMIS) +stdlib_man/Pervasives.3o: $(OCAMLDOC) $(STDLIB_MLIS) + $(MAKE) unprefix_stdlib_for_ocamldoc $(MKDIR) stdlib_man $(OCAMLDOC_RUN) -man -d stdlib_man -nostdlib -I stdlib_non_prefixed \ -t "OCaml library" -man-mini $(STDLIB_MLIS) \ -initially-opened-module Pervasives -stdlib_html/Stdlib.html: $(OCAMLDOC) $(STDLIB_MLIS) $(STDLIB_CMIS) +stdlib_html/Pervasives.html: $(OCAMLDOC) $(STDLIB_MLIS) + $(MAKE) unprefix_stdlib_for_ocamldoc $(MKDIR) stdlib_html $(OCAMLDOC_RUN) -d stdlib_html -html -nostdlib -I stdlib_non_prefixed \ -t "OCaml library" $(STDLIB_MLIS) \ diff --git a/ocamldoc/Makefile.unprefix b/ocamldoc/Makefile.unprefix index 1b036773ec..15a384f7b9 100644 --- a/ocamldoc/Makefile.unprefix +++ b/ocamldoc/Makefile.unprefix @@ -98,5 +98,6 @@ $(STDLIB_UNPREFIXED)/pervasives.mli: $(SRC)/stdlib/stdlib.mli $(STDLIB_UNPREFIXE $(AWK) -f $(STDLIB_UNPREFIXED)/extract_pervasives.awk $< > $@ # Build cmis file inside the STDLIB_UNPREFIXED directories -$(STDLIB_CMIS): $(STDLIB_DEPS) - cd $(STDLIB_UNPREFIXED); $(MAKE) $(notdir $(STDLIB_CMIS)) +.PHONY: unprefix_stdlib_for_ocamldoc +unprefix_stdlib_for_ocamldoc: $(STDLIB_MLIS) $(STDLIB_DEPS) + @$(MAKE) -C $(STDLIB_UNPREFIXED) $(notdir $(STDLIB_CMIS)) diff --git a/ocamldoc/odoc_ast.ml b/ocamldoc/odoc_ast.ml index a6a5e55c4c..7ac5d761d3 100644 --- a/ocamldoc/odoc_ast.ml +++ b/ocamldoc/odoc_ast.ml @@ -77,7 +77,7 @@ module Typedtree_search = | ext :: _ -> Hashtbl.add table (X (Name.from_ident ext.ext_id)) tt end | Typedtree.Tstr_exception ext -> - Hashtbl.add table (E (Name.from_ident ext.ext_id)) tt + Hashtbl.add table (E (Name.from_ident ext.tyexn_constructor.ext_id)) tt | Typedtree.Tstr_type (rf, ident_type_decl_list) -> List.iter (fun td -> @@ -1344,7 +1344,7 @@ module Analyser = (maybe_more, new_env, [ Element_type_extension new_te ]) | Parsetree.Pstr_exception ext -> - let name = ext.Parsetree.pext_name in + let name = ext.Parsetree.ptyexn_constructor.Parsetree.pext_name in (* a new exception is defined *) let complete_name = Name.concat current_module_name name.txt in (* we get the exception declaration in the typed tree *) @@ -1355,7 +1355,7 @@ module Analyser = in let new_env = Odoc_env.add_extension env complete_name in let new_ext = - match tt_ext.ext_kind with + match tt_ext.Typedtree.tyexn_constructor.ext_kind with Text_decl(tt_args, tt_ret_type) -> let loc_start = loc.Location.loc_start.Lexing.pos_cnum in let loc_end = loc.Location.loc_end.Lexing.pos_cnum in diff --git a/ocamldoc/odoc_man.ml b/ocamldoc/odoc_man.ml index 9a4d3f1ca1..04e66e70aa 100644 --- a/ocamldoc/odoc_man.ml +++ b/ocamldoc/odoc_man.ml @@ -329,9 +329,9 @@ class man = self#man_of_text_element b (Odoc_info.Code (Odoc_info.use_hidden_modules name)) | Odoc_info.Superscript t -> - bs b "^{"; self#man_of_text2 b t + bs b "^"; self#man_of_text2 b t | Odoc_info.Subscript t -> - bs b "_{"; self#man_of_text2 b t + bs b "_"; self#man_of_text2 b t | Odoc_info.Module_list _ -> () | Odoc_info.Index_list -> diff --git a/ocamldoc/odoc_sig.ml b/ocamldoc/odoc_sig.ml index 9f9396f682..7f61e6ec54 100644 --- a/ocamldoc/odoc_sig.ml +++ b/ocamldoc/odoc_sig.ml @@ -863,7 +863,7 @@ module Analyser = (maybe_more + maybe_more2, new_env, [ Element_type_extension new_te ]) | Parsetree.Psig_exception ext -> - let name = ext.Parsetree.pext_name in + let name = ext.Parsetree.ptyexn_constructor.Parsetree.pext_name in let types_ext = try Signature_search.search_extension table name.txt with Not_found -> diff --git a/ocamldoc/odoc_text_parser.mly b/ocamldoc/odoc_text_parser.mly index f71ab3777c..3d590d45c4 100644 --- a/ocamldoc/odoc_text_parser.mly +++ b/ocamldoc/odoc_text_parser.mly @@ -82,6 +82,9 @@ let print_DEBUG s = print_string s; print_newline () %token EOF %token <string> Char +%nonassoc below_Char +%nonassoc Char + /* Start Symbols */ %start main located_element_list %type <Odoc_types.text> main @@ -177,7 +180,6 @@ text_element: list: | string { [] (* TODO: a test to check that there is only space characters *) } | string list { $2 } -| list string { $1 } | item { [ $1 ] } | item list { $1 :: $2 } @@ -207,7 +209,7 @@ shortcut_enum2: string: - Char { $1 } + Char %prec below_Char { $1 } | Char string { $1^$2 } ; diff --git a/ocamldoc/stdlib_non_prefixed/Makefile b/ocamldoc/stdlib_non_prefixed/Makefile index 801007efc1..1ce1b71565 100644 --- a/ocamldoc/stdlib_non_prefixed/Makefile +++ b/ocamldoc/stdlib_non_prefixed/Makefile @@ -4,7 +4,7 @@ include $(TOPDIR)/Makefile.tools .SUFFIXES: OCAMLDEP= $(OCAMLRUN) $(TOPDIR)/tools/ocamldep -slash -OCAMLC_SNP= $(OCAMLRUN) $(TOPDIR)/ocamlc -nostdlib -nopervasives -I $(HERE) +OCAMLC_SNP= $(OCAMLRUN) $(TOPDIR)/ocamlc -nostdlib -nopervasives pervasives.cmi: pervasives.mli camlinternalFormatBasics.cmi $(OCAMLC_SNP) -c $< diff --git a/ocamltest/.depend b/ocamltest/.depend index d2e018f291..75cdd54f3e 100644 --- a/ocamltest/.depend +++ b/ocamltest/.depend @@ -22,10 +22,10 @@ actions.cmx : result.cmx environments.cmx actions.cmi actions.cmi : result.cmi environments.cmi actions_helpers.cmo : variables.cmi run_command.cmi result.cmi \ ocamltest_stdlib.cmi filecompare.cmi environments.cmi \ - builtin_variables.cmi actions_helpers.cmi + builtin_variables.cmi actions.cmi actions_helpers.cmi actions_helpers.cmx : variables.cmx run_command.cmx result.cmx \ ocamltest_stdlib.cmx filecompare.cmx environments.cmx \ - builtin_variables.cmx actions_helpers.cmi + builtin_variables.cmx actions.cmx actions_helpers.cmi actions_helpers.cmi : variables.cmi result.cmi environments.cmi actions.cmi builtin_actions.cmo : result.cmi ocamltest_stdlib.cmi ocamltest_config.cmi \ environments.cmi builtin_variables.cmi actions_helpers.cmi actions.cmi \ @@ -81,11 +81,13 @@ ocaml_directories.cmo : ocamltest_stdlib.cmi ocamltest_config.cmi \ ocaml_directories.cmx : ocamltest_stdlib.cmx ocamltest_config.cmx \ ocaml_backends.cmx ocaml_directories.cmi ocaml_directories.cmi : ocaml_backends.cmi -ocaml_files.cmo : ocamltest_stdlib.cmi ocaml_files.cmi -ocaml_files.cmx : ocamltest_stdlib.cmx ocaml_files.cmi +ocaml_files.cmo : ocamltest_stdlib.cmi ocamltest_config.cmi ocaml_files.cmi +ocaml_files.cmx : ocamltest_stdlib.cmx ocamltest_config.cmx ocaml_files.cmi ocaml_files.cmi : -ocaml_filetypes.cmo : ocaml_backends.cmi ocaml_filetypes.cmi -ocaml_filetypes.cmx : ocaml_backends.cmx ocaml_filetypes.cmi +ocaml_filetypes.cmo : ocamltest_config.cmi ocaml_backends.cmi \ + ocaml_filetypes.cmi +ocaml_filetypes.cmx : ocamltest_config.cmx ocaml_backends.cmx \ + ocaml_filetypes.cmi ocaml_filetypes.cmi : ocaml_backends.cmi ocaml_flags.cmo : ocaml_variables.cmi ocaml_files.cmi ocaml_directories.cmi \ ocaml_backends.cmi environments.cmi ocaml_flags.cmi @@ -98,9 +100,9 @@ ocaml_modifiers.cmx : ocamltest_stdlib.cmx ocamltest_config.cmx \ ocaml_variables.cmx environments.cmx ocaml_modifiers.cmi ocaml_modifiers.cmi : environments.cmi ocaml_tests.cmo : tests.cmi ocamltest_config.cmi ocaml_actions.cmi \ - builtin_actions.cmi ocaml_tests.cmi + builtin_actions.cmi actions_helpers.cmi ocaml_tests.cmi ocaml_tests.cmx : tests.cmx ocamltest_config.cmx ocaml_actions.cmx \ - builtin_actions.cmx ocaml_tests.cmi + builtin_actions.cmx actions_helpers.cmx ocaml_tests.cmi ocaml_tests.cmi : tests.cmi ocaml_tools.cmo : variables.cmi ocamltest_stdlib.cmi ocaml_variables.cmi \ ocaml_files.cmi environments.cmi actions_helpers.cmi ocaml_tools.cmi diff --git a/ocamltest/Makefile b/ocamltest/Makefile index e4ada8fb3d..fa92eedab8 100644 --- a/ocamltest/Makefile +++ b/ocamltest/Makefile @@ -26,14 +26,26 @@ ifeq "$(UNIX_OR_WIN32)" "win32" else FLEXLINK_ENV=OCAML_FLEXLINK="../boot/ocamlrun ../flexdll/flexlink.exe" endif + mkexe := $(MKEXE_ANSI) -link $(LDFLAGS) else unix := true ocamlsrcdir := $(abspath $(shell pwd)/..) FLEXLINK_ENV= + mkexe := $(MKEXE) endif ifeq "$(TOOLCHAIN)" "msvc" CPP := $(CPP) 2> nul +CSC := csc +ifeq "$(HOST)" "msvc" +CSCFLAGS := /platform:x86 +else +CSCFLAGS := +endif +CSCFLAGS += /nologo /nowarn:1668 +else +CSC := +CSCFLAGS := endif ifeq "$(WITH_OCAMLDOC)" "ocamldoc" @@ -202,6 +214,19 @@ ocamltest_config.ml: ocamltest_config.ml.in -e 's|@@OCAMLDOC@@|$(WITH_OCAMLDOC)|' \ -e 's|@@OCAMLDEBUG@@|$(WITH_OCAMLDEBUG)|' \ -e 's|@@OBJEXT@@|$(O)|' \ + -e 's|@@NATIVE_DYNLINK@@|$(NATDYNLINK)|' \ + -e 's|@@SHARED_LIBRARY_CFLAGS@@|$(SHAREDCCCOMPOPTS)|' \ + -e 's|@@SHAREDOBJEXT@@|$(SO)|' \ + -e 's|@@CSC@@|$(CSC)|' \ + -e 's|@@CSCFLAGS@@|$(CSCFLAGS)|' \ + -e 's|@@MKDLL@@|$(MKDLL)|' \ + -e 's|@@MKEXE@@|$(mkexe)|' \ + -e 's|@@BYTECCLIBS@@|$(BYTECCLIBS)|' \ + -e 's|@@NATIVECCLIBS@@|$(NATIVECCLIBS)|' \ + -e 's|@@ASM@@|$(ASM)|' \ + -e 's|@@CC@@|$(CC)|' \ + -e 's|@@CFLAGS@@|$(CFLAGS)|' \ + -e 's|@@CCOMPTYPE@@|$(CCOMPTYPE)|' \ $< > $@ .PHONY: clean diff --git a/ocamltest/actions_helpers.ml b/ocamltest/actions_helpers.ml index 7857007694..2c5c620810 100644 --- a/ocamltest/actions_helpers.ml +++ b/ocamltest/actions_helpers.ml @@ -17,6 +17,13 @@ open Ocamltest_stdlib +let skip_with_reason reason = + let code _log env = + let result = Result.skip_with_reason reason in + (result, env) + in + Actions.make "skip" code + let pass_or_skip test pass_reason skip_reason _log env = let open Result in let result = @@ -196,15 +203,19 @@ let run_script log env = Builtin_variables.script None log scriptenv in - if Result.is_pass result then begin - let modifiers = Environments.modifiers_of_file response_file in - let modified_env = Environments.apply_modifiers newenv modifiers in - (result, modified_env) - end else begin - let reason = String.trim (Sys.string_of_file response_file) in - let newresult = { result with Result.reason = Some reason } in - (newresult, newenv) - end + let final_value = + if Result.is_pass result then begin + let modifiers = Environments.modifiers_of_file response_file in + let modified_env = Environments.apply_modifiers newenv modifiers in + (result, modified_env) + end else begin + let reason = String.trim (Sys.string_of_file response_file) in + let newresult = { result with Result.reason = Some reason } in + (newresult, newenv) + end + in + Sys.force_remove response_file; + final_value let run_hook hook_name log input_env = Printf.fprintf log "Entering run_hook for hook %s\n%!" hook_name; @@ -227,7 +238,7 @@ let run_hook hook_name log input_env = timeout = 0; log = log; } in let exit_status = run settings in - match exit_status with + let final_value = match exit_status with | 0 -> let modifiers = Environments.modifiers_of_file response_file in let modified_env = Environments.apply_modifiers hookenv modifiers in @@ -238,6 +249,9 @@ let run_hook hook_name log input_env = if exit_status=125 then (Result.skip_with_reason reason, hookenv) else (Result.fail_with_reason reason, hookenv) + in + Sys.force_remove response_file; + final_value let check_output kind_of_output output_variable reference_variable log env = diff --git a/ocamltest/actions_helpers.mli b/ocamltest/actions_helpers.mli index 5e7d6904ba..8c305ff74b 100644 --- a/ocamltest/actions_helpers.mli +++ b/ocamltest/actions_helpers.mli @@ -15,6 +15,8 @@ (* Helper functions when writing actions *) +val skip_with_reason : string -> Actions.t + val pass_or_skip : bool -> string -> string -> out_channel -> Environments.t -> Result.t * Environments.t diff --git a/ocamltest/builtin_actions.ml b/ocamltest/builtin_actions.ml index 6d636583eb..ff577e85ce 100644 --- a/ocamltest/builtin_actions.ml +++ b/ocamltest/builtin_actions.ml @@ -104,6 +104,14 @@ let not_bsd = make "not on a BSD system" "on a BSD system") +let macos_system = "macosx" + +let macos = make + "macos" + (Actions_helpers.pass_or_skip (Ocamltest_config.system = macos_system) + "on a MacOS system" + "not on a MacOS system") + let arch32 = make "arch32" (Actions_helpers.pass_or_skip (Sys.word_size = 32) @@ -168,6 +176,7 @@ let _ = not_windows; bsd; not_bsd; + macos; arch32; arch64; has_symlink; diff --git a/ocamltest/builtin_variables.ml b/ocamltest/builtin_variables.ml index 1bfd843c62..6ea498f698 100644 --- a/ocamltest/builtin_variables.ml +++ b/ocamltest/builtin_variables.ml @@ -22,89 +22,95 @@ should be similar. Is there a way to enforce this? *) -open Variables (* Should not be necessary with a ppx *) - -let arguments = make ("arguments", +let arguments = Variables.make ("arguments", "Arguments passed to executed programs and scripts") -let cwd = make ("cwd", +let cwd = Variables.make ("cwd", "Used to change current working directory, but not updated") -let exit_status = make ("exit_status", +let commandline = Variables.make ("commandline", + "Specify the commandline of a tool") + +let exit_status = Variables.make ("exit_status", "Expected program exit status") -let files = make ("files", +let files = Variables.make ("files", "Files used by the tests") -let ocamltest_response = make ("ocamltest_response", +let make = Variables.make ("MAKE", + "Command used to invoke make") + +let ocamltest_response = Variables.make ("ocamltest_response", "File used by hooks to send back information.") -let ocamltest_log = make ("ocamltest_log", +let ocamltest_log = Variables.make ("ocamltest_log", "Path to log file for the current test") -let output = make ("output", +let output = Variables.make ("output", "Where the output of executing the program is saved") -let program = make ("program", +let program = Variables.make ("program", "Name of program produced by ocamlc.byte and ocamlopt.byte") -let program2 = make ("program2", +let program2 = Variables.make ("program2", "Name of program produced by ocamlc.opt and ocamlopt.opt") -let promote = make ("promote", +let promote = Variables.make ("promote", "Set to \"true\" to overwrite reference files with the test output") -let reason = make ("reason", +let reason = Variables.make ("reason", "Let a test report why it passed/skipped/failed.") -let reference = make ("reference", +let reference = Variables.make ("reference", "Path of file to which program output should be compared") let skip_header_lines = - make ( "skip_header_lines", + Variables.make ( "skip_header_lines", "The number of lines to skip when comparing program output \ with the reference file") let skip_header_bytes = - make ( "skip_header_bytes", + Variables.make ( "skip_header_bytes", "The number of bytes to skip when comparing program output \ with the reference file") -let script = make ("script", +let script = Variables.make ("script", "External script to run") -let stdin = make ("stdin", "Default standard input") -let stdout = make ("stdout", "Default standard output") -let stderr = make ("stderr", "Default standard error") +let stdin = Variables.make ("stdin", "Default standard input") +let stdout = Variables.make ("stdout", "Default standard output") +let stderr = Variables.make ("stderr", "Default standard error") -let test_build_directory = make ("test_build_directory", +let test_build_directory = Variables.make ("test_build_directory", "Directory for files produced during a test") -let test_build_directory_prefix = make ("test_build_directory_prefix", +let test_build_directory_prefix = Variables.make ("test_build_directory_prefix", "Directory under which all test directories should be created") -let test_file = make ("test_file", +let test_file = Variables.make ("test_file", "Name of file containing the specification of which tests to run") -let test_source_directory = make ("test_source_directory", +let test_source_directory = Variables.make ("test_source_directory", "Directory containing the test source files") -let test_pass = make ("TEST_PASS", +let test_pass = Variables.make ("TEST_PASS", "Exit code to let a script report success") -let test_skip = make ("TEST_SKIP", +let test_skip = Variables.make ("TEST_SKIP", "Exit code to let a script report skipping") -let test_fail = make ("TEST_FAIL", +let test_fail = Variables.make ("TEST_FAIL", "Exit code to let a script report failure") -let _ = List.iter register_variable +let _ = List.iter Variables.register_variable [ arguments; cwd; + commandline; exit_status; files; + make; ocamltest_response; ocamltest_log; output; diff --git a/ocamltest/builtin_variables.mli b/ocamltest/builtin_variables.mli index 126a3968c4..2e82174de3 100644 --- a/ocamltest/builtin_variables.mli +++ b/ocamltest/builtin_variables.mli @@ -21,10 +21,14 @@ val arguments : Variables.t val cwd : Variables.t +val commandline : Variables.t + val exit_status : Variables.t val files : Variables.t +val make : Variables.t + val ocamltest_response : Variables.t val ocamltest_log : Variables.t diff --git a/ocamltest/filecompare.ml b/ocamltest/filecompare.ml index 9e88d31e93..e1e9c03f31 100644 --- a/ocamltest/filecompare.ml +++ b/ocamltest/filecompare.ml @@ -173,5 +173,9 @@ let diff files = files.output_filename; "> " ^ temporary_file ] in - if (Sys.command diff_commandline) = 2 then Pervasives.Error "diff" - else Ok (Sys.string_of_file temporary_file) + let result = + if (Sys.command diff_commandline) = 2 then Pervasives.Error "diff" + else Ok (Sys.string_of_file temporary_file) + in + Sys.force_remove temporary_file; + result diff --git a/ocamltest/main.ml b/ocamltest/main.ml index 5b791ed424..1fa1b7599e 100644 --- a/ocamltest/main.ml +++ b/ocamltest/main.ml @@ -127,6 +127,7 @@ let test_file test_filename = let hookname_prefix = Filename.concat test_source_directory test_prefix in let test_build_directory_prefix = get_test_build_directory_prefix test_directory in + ignore (Sys.command ("rm -rf " ^ test_build_directory_prefix)); Sys.make_directory test_build_directory_prefix; Sys.with_chdir test_build_directory_prefix (fun () -> @@ -146,8 +147,10 @@ let test_file test_filename = let reference_filename = Filename.concat test_source_directory (test_prefix ^ ".reference") in + let make = try Sys.getenv "MAKE" with Not_found -> "make" in let initial_environment = Environments.from_bindings [ + Builtin_variables.make, make; Builtin_variables.test_file, test_basename; Builtin_variables.reference, reference_filename; Builtin_variables.test_source_directory, test_source_directory; diff --git a/ocamltest/ocaml_actions.ml b/ocamltest/ocaml_actions.ml index bcf5e75d2d..8551c53eaa 100644 --- a/ocamltest/ocaml_actions.ml +++ b/ocamltest/ocaml_actions.ml @@ -49,6 +49,8 @@ let directory_flags env = let flags env = Environments.safe_lookup Ocaml_variables.flags env +let last_flags env = Environments.safe_lookup Ocaml_variables.last_flags env + let ocamllex_flags env = Environments.safe_lookup Ocaml_variables.ocamllex_flags env @@ -152,7 +154,7 @@ let prepare_module ocamlsrcdir output_variable log env input = let input_type = snd input in let open Ocaml_filetypes in match input_type with - | Implementation | Interface | C -> [input] + | Implementation | Interface | C | Obj -> [input] | Binary_interface -> [input] | Backend_specific _ -> [input] | C_minus_minus -> assert false @@ -173,6 +175,8 @@ let get_program_file backend env = Actions_helpers.test_build_directory env in Filename.make_path [test_build_directory; program_filename] +let is_c_file (_filename, filetype) = filetype=Ocaml_filetypes.C + let compile_program ocamlsrcdir (compiler : Ocaml_compilers.compiler) log env = let program_variable = compiler#program_variable in let program_file = Environments.safe_lookup program_variable env in @@ -182,7 +186,6 @@ let compile_program ocamlsrcdir (compiler : Ocaml_compilers.compiler) log env = let prepare = prepare_module ocamlsrcdir output_variable log env in let modules = List.concatmap prepare (List.map Ocaml_filetypes.filetype all_modules) in - let is_c_file (_filename, filetype) = filetype=Ocaml_filetypes.C in let has_c_file = List.exists is_c_file modules in let c_headers_flags = if has_c_file then Ocaml_flags.c_includes ocamlsrcdir else "" in @@ -214,7 +217,8 @@ let compile_program ocamlsrcdir (compiler : Ocaml_compilers.compiler) log env = backend_flags env compiler#target; compile_flags; output; - module_names + module_names; + last_flags env ] in let exit_status = Actions_helpers.run_cmd @@ -238,10 +242,15 @@ let compile_module ocamlsrcdir compiler module_ log env = Ocaml_tools.expected_exit_status env (compiler :> Ocaml_tools.tool) in let what = Printf.sprintf "Compiling module %s" module_ in Printf.fprintf log "%s\n%!" what; + let module_with_filetype = Ocaml_filetypes.filetype module_ in + let is_c = is_c_file module_with_filetype in + let c_headers_flags = + if is_c then Ocaml_flags.c_includes ocamlsrcdir else "" in let commandline = [ compiler#name ocamlsrcdir; Ocaml_flags.stdlib ocamlsrcdir; + c_headers_flags; directory_flags env; flags env; libraries compiler#target env; @@ -405,10 +414,36 @@ let setup_ocamlnat_build_env = let compile (compiler : Ocaml_compilers.compiler) log env = let ocamlsrcdir = Ocaml_directories.srcdir () in - match Environments.lookup_nonempty Ocaml_variables.module_ env with - | None -> compile_program ocamlsrcdir compiler log env - | Some module_ -> compile_module ocamlsrcdir compiler module_ log env - + match Environments.lookup_nonempty Builtin_variables.commandline env with + | None -> + begin + match Environments.lookup_nonempty Ocaml_variables.module_ env with + | None -> compile_program ocamlsrcdir compiler log env + | Some module_ -> compile_module ocamlsrcdir compiler module_ log env + end + | Some cmdline -> + let expected_exit_status = + Ocaml_tools.expected_exit_status env (compiler :> Ocaml_tools.tool) in + let what = Printf.sprintf "Compiling using commandline %s" cmdline in + Printf.fprintf log "%s\n%!" what; + let commandline = [compiler#name ocamlsrcdir; cmdline] in + let exit_status = + Actions_helpers.run_cmd + ~environment:dumb_term + ~stdin_variable: Ocaml_variables.compiler_stdin + ~stdout_variable:compiler#output_variable + ~stderr_variable:compiler#output_variable + ~append:true + log env commandline in + if exit_status=expected_exit_status + then (Result.pass, env) + else begin + let reason = + (Actions_helpers.mkreason + what (String.concat " " commandline) exit_status) in + (Result.fail_with_reason reason, env) + end + (* Compile actions *) let ocamlc_byte = @@ -556,6 +591,134 @@ let mklib log env = let ocamlmklib = Actions.make "ocamlmklib" mklib +let finalise_codegen_cc ocamlsrcdir test_basename _log env = + let test_module = + Filename.make_filename test_basename "s" + in + let archmod = Ocaml_files.asmgen_archmod ocamlsrcdir in + let modules = test_module ^ " " ^ archmod in + let program = Filename.make_filename test_basename "out" in + let env = Environments.add_bindings + [ + Ocaml_variables.modules, modules; + Builtin_variables.program, program; + ] env in + (Result.pass, env) + +let finalise_codegen_msvc ocamlsrcdir test_basename log env = + let obj = Filename.make_filename test_basename Ocamltest_config.objext in + let src = Filename.make_filename test_basename "s" in + let what = "Running Microsoft assembler" in + Printf.fprintf log "%s\n%!" what; + let commandline = [Ocamltest_config.asm; obj; src] in + let expected_exit_status = 0 in + let exit_status = + Actions_helpers.run_cmd + ~environment:dumb_term + ~stdout_variable:Ocaml_variables.compiler_output + ~stderr_variable:Ocaml_variables.compiler_output + ~append:true + log env commandline in + if exit_status=expected_exit_status + then begin + let archmod = Ocaml_files.asmgen_archmod ocamlsrcdir in + let modules = obj ^ " " ^ archmod in + let program = Filename.make_filename test_basename "out" in + let env = Environments.add_bindings + [ + Ocaml_variables.modules, modules; + Builtin_variables.program, program; + ] env in + (Result.pass, env) + end else begin + let reason = + (Actions_helpers.mkreason + what (String.concat " " commandline) exit_status) in + (Result.fail_with_reason reason, env) + end + +let run_codegen log env = + let ocamlsrcdir = Ocaml_directories.srcdir () in + let testfile = Actions_helpers.testfile env in + let what = Printf.sprintf "Running codegen on %s" testfile in + Printf.fprintf log "%s\n%!" what; + let test_build_directory = + Actions_helpers.test_build_directory env in + let compiler_output = + Filename.make_path [test_build_directory; "compiler-output"] + in + let env = + Environments.add_if_undefined + Ocaml_variables.compiler_output + compiler_output + env + in + let commandline = + [ + Ocaml_commands.ocamlrun_codegen ocamlsrcdir; + "-S " ^ testfile + ] in + let expected_exit_status = 0 in + let exit_status = + Actions_helpers.run_cmd + ~environment:dumb_term + ~stdout_variable:Ocaml_variables.compiler_output + ~stderr_variable:Ocaml_variables.compiler_output + ~append:true + log env commandline in + if exit_status=expected_exit_status + then begin + let testfile_basename = Filename.chop_extension testfile in + let finalise = + if Ocamltest_config.ccomptype="msvc" + then finalise_codegen_msvc + else finalise_codegen_cc + in + finalise ocamlsrcdir testfile_basename log env + end else begin + let reason = + (Actions_helpers.mkreason + what (String.concat " " commandline) exit_status) in + (Result.fail_with_reason reason, env) + end + +let codegen = Actions.make "codegen" run_codegen + +let run_cc log env = + let ocamlsrcdir = Ocaml_directories.srcdir () in + let program = Environments.safe_lookup Builtin_variables.program env in + let what = Printf.sprintf "Running C compiler to build %s" program in + Printf.fprintf log "%s\n%!" what; + let output_exe = + if Ocamltest_config.ccomptype="msvc" then "/Fe" else "-o " + in + let commandline = + [ + Ocamltest_config.cc; + Ocamltest_config.cflags; + "-I" ^ Ocaml_directories.runtime ocamlsrcdir; + output_exe ^ program; + Environments.safe_lookup Builtin_variables.arguments env; + ] @ modules env in + let expected_exit_status = 0 in + let exit_status = + Actions_helpers.run_cmd + ~environment:dumb_term + ~stdout_variable:Ocaml_variables.compiler_output + ~stderr_variable:Ocaml_variables.compiler_output + ~append:true + log env commandline in + if exit_status=expected_exit_status + then (Result.pass, env) + else begin + let reason = + (Actions_helpers.mkreason + what (String.concat " " commandline) exit_status) in + (Result.fail_with_reason reason, env) + end + +let cc = Actions.make "cc" run_cc + let run_expect_once ocamlsrcdir input_file principal log env = let expect_flags = Sys.safe_getenv "EXPECT_FLAGS" in let repo_root = "-repo-root " ^ ocamlsrcdir in @@ -873,10 +1036,23 @@ let check_ocamlnat_output = (make_check_tool_output "check-ocamlnat-output" Ocaml_toplevels.ocamlnat) -let config_variables _log env = Environments.add_bindings +let config_variables _log env = + let ocamlsrcdir = Ocaml_directories.srcdir () in + Environments.add_bindings [ + Ocaml_variables.ocamlrun, Ocaml_files.ocamlrun ocamlsrcdir; + Ocaml_variables.ocamlc_byte, Ocaml_files.ocamlc ocamlsrcdir; + Ocaml_variables.ocamlopt_byte, Ocaml_files.ocamlopt ocamlsrcdir; + Ocaml_variables.bytecc_libs, Ocamltest_config.bytecc_libs; + Ocaml_variables.nativecc_libs, Ocamltest_config.nativecc_libs; + Ocaml_variables.mkdll, Ocamltest_config.mkdll; + Ocaml_variables.mkexe, Ocamltest_config.mkexe; Ocaml_variables.c_preprocessor, Ocamltest_config.c_preprocessor; + Ocaml_variables.csc, Ocamltest_config.csc; + Ocaml_variables.csc_flags, Ocamltest_config.csc_flags; + Ocaml_variables.shared_library_cflags, Ocamltest_config.shared_library_cflags; Ocaml_variables.objext, Ocamltest_config.objext; + Ocaml_variables.sharedobjext, Ocamltest_config.sharedobjext; Ocaml_variables.ocamlc_default_flags, Ocamltest_config.ocamlc_default_flags; Ocaml_variables.ocamlopt_default_flags, @@ -934,6 +1110,18 @@ let native_compiler = Actions.make "native compiler available" "native compiler not available") +let native_dynlink = Actions.make + "native-dynlink" + (Actions_helpers.pass_or_skip (Ocamltest_config.native_dynlink) + "native dynlink support available" + "native dynlink support not available") + +let csharp_compiler = Actions.make + "csharp-compiler" + (Actions_helpers.pass_or_skip (Ocamltest_config.csc<>"") + "C# compiler available" + "C# compiler not available") + let afl_instrument = Actions.make "afl-instrument" (Actions_helpers.pass_or_skip Ocamltest_config.afl_instrument @@ -1134,6 +1322,8 @@ let _ = no_spacetime; shared_libraries; native_compiler; + native_dynlink; + csharp_compiler; afl_instrument; no_afl_instrument; setup_ocamldoc_build_env; @@ -1141,5 +1331,7 @@ let _ = check_ocamldoc_output; ocamldebug; ocamlmklib; + codegen; + cc; ocamlobjinfo ] diff --git a/ocamltest/ocaml_actions.mli b/ocamltest/ocaml_actions.mli index ab4d302ae3..f0eda2f6c3 100644 --- a/ocamltest/ocaml_actions.mli +++ b/ocamltest/ocaml_actions.mli @@ -50,3 +50,7 @@ val native_compiler : Actions.t val afl_instrument : Actions.t val no_afl_instrument : Actions.t + +val codegen : Actions.t + +val cc : Actions.t diff --git a/ocamltest/ocaml_commands.ml b/ocamltest/ocaml_commands.ml index 0a1c61aacc..59bbb6c9d5 100644 --- a/ocamltest/ocaml_commands.ml +++ b/ocamltest/ocaml_commands.ml @@ -40,3 +40,6 @@ let ocamlrun_ocamlobjinfo ocamlsrcdir = let ocamlrun_ocamlmklib ocamlsrcdir = ocamlrun ocamlsrcdir Ocaml_files.ocamlmklib + +let ocamlrun_codegen ocamlsrcdir = + ocamlrun ocamlsrcdir Ocaml_files.codegen diff --git a/ocamltest/ocaml_commands.mli b/ocamltest/ocaml_commands.mli index 4c523250c0..9a1474e20a 100644 --- a/ocamltest/ocaml_commands.mli +++ b/ocamltest/ocaml_commands.mli @@ -32,3 +32,4 @@ val ocamlrun_ocamldebug : string -> string val ocamlrun_ocamlobjinfo : string -> string val ocamlrun_ocamlmklib : string -> string +val ocamlrun_codegen : string -> string diff --git a/ocamltest/ocaml_files.ml b/ocamltest/ocaml_files.ml index a6862ca576..02e1e044e3 100644 --- a/ocamltest/ocaml_files.ml +++ b/ocamltest/ocaml_files.ml @@ -78,3 +78,12 @@ let ocamlobjinfo ocamlsrcdir = let ocamlmklib ocamlsrcdir = Filename.make_path [ocamlsrcdir; "tools"; "ocamlmklib"] + +let codegen ocamlsrcdir = + Filename.make_path [ocamlsrcdir; "testsuite"; "tools"; "codegen"] + +let asmgen_archmod ocamlsrcdir = + let objname = + "asmgen_" ^ Ocamltest_config.arch ^ "." ^ Ocamltest_config.objext + in + Filename.make_path [ocamlsrcdir; "testsuite"; "tools"; objname] diff --git a/ocamltest/ocaml_files.mli b/ocamltest/ocaml_files.mli index aa98057857..95c93179be 100644 --- a/ocamltest/ocaml_files.mli +++ b/ocamltest/ocaml_files.mli @@ -48,3 +48,6 @@ val ocamldoc : string -> string val ocamldebug : string -> string val ocamlobjinfo : string -> string val ocamlmklib : string -> string +val codegen : string -> string + +val asmgen_archmod : string -> string diff --git a/ocamltest/ocaml_filetypes.ml b/ocamltest/ocaml_filetypes.ml index 997cc1b744..6b5884e826 100644 --- a/ocamltest/ocaml_filetypes.ml +++ b/ocamltest/ocaml_filetypes.ml @@ -25,6 +25,7 @@ type t = | Lexer | Grammar | Binary_interface + | Obj | Backend_specific of Ocaml_backends.t * backend_specific | Text (* used by ocamldoc for text only documentation *) @@ -41,6 +42,7 @@ let string_of_filetype = function | Lexer -> "lexer" | Grammar -> "grammar" | Binary_interface -> "binary interface" + | Obj -> "object" | Backend_specific (backend, filetype) -> ((Ocaml_backends.string_of_backend backend) ^ " " ^ (string_of_backend_specific filetype)) @@ -54,6 +56,7 @@ let extension_of_filetype = function | Lexer -> "mll" | Grammar -> "mly" | Binary_interface -> "cmi" + | Obj -> Ocamltest_config.objext | Backend_specific (backend, filetype) -> begin match (backend, filetype) with | (Ocaml_backends.Native, Object) -> "cmx" @@ -73,6 +76,8 @@ let filetype_of_extension = function | "mll" -> Lexer | "mly" -> Grammar | "cmi" -> Binary_interface + | "o" -> Obj + | "obj" -> Obj | "cmx" -> Backend_specific (Ocaml_backends.Native, Object) | "cmxa" -> Backend_specific (Ocaml_backends.Native, Library) | "opt" -> Backend_specific (Ocaml_backends.Native, Program) @@ -80,7 +85,7 @@ let filetype_of_extension = function | "cma" -> Backend_specific (Ocaml_backends.Bytecode, Library) | "byte" -> Backend_specific (Ocaml_backends.Bytecode, Program) | "txt" -> Text - | _ -> raise Not_found + | _ as e -> Printf.eprintf "Unknown file extension %s\n%!" e; exit 2 let split_filename name = let l = String.length name in diff --git a/ocamltest/ocaml_filetypes.mli b/ocamltest/ocaml_filetypes.mli index 89911d4b26..542d13ae0c 100644 --- a/ocamltest/ocaml_filetypes.mli +++ b/ocamltest/ocaml_filetypes.mli @@ -25,6 +25,7 @@ type t = | Lexer | Grammar | Binary_interface + | Obj | Backend_specific of Ocaml_backends.t * backend_specific | Text (** text-only documentation file *) diff --git a/ocamltest/ocaml_tests.ml b/ocamltest/ocaml_tests.ml index 35cfa75dd3..9dc16636d9 100644 --- a/ocamltest/ocaml_tests.ml +++ b/ocamltest/ocaml_tests.ml @@ -105,6 +105,35 @@ let ocamldoc = [ skip ] } +let asmgen_skip_on_bytecode_only = + Actions_helpers.skip_with_reason "native compiler disabled" + +let asmgen_skip_on_spacetime = + Actions_helpers.skip_with_reason "not ported to Spacetime yet" + +let msvc64 = + Ocamltest_config.ccomptype = "msvc" && Ocamltest_config.arch="amd64" + +let asmgen_skip_on_msvc64 = + Actions_helpers.skip_with_reason "not ported to MSVC64 yet" + +let asmgen_actions = + if Ocamltest_config.arch="none" then [asmgen_skip_on_bytecode_only] + else if Ocamltest_config.spacetime then [asmgen_skip_on_spacetime] + else if msvc64 then [asmgen_skip_on_msvc64] + else [ + setup_simple_build_env; + codegen; + cc; + ] + +let asmgen = +{ + test_name = "asmgen"; + test_run_by_default = false; + test_actions = asmgen_actions +} + let _ = List.iter register [ @@ -113,4 +142,5 @@ let _ = toplevel; expect; ocamldoc; + asmgen; ] diff --git a/ocamltest/ocaml_tests.mli b/ocamltest/ocaml_tests.mli index b9cd02256a..8ace884a4b 100644 --- a/ocamltest/ocaml_tests.mli +++ b/ocamltest/ocaml_tests.mli @@ -24,3 +24,5 @@ val toplevel : Tests.t val expect : Tests.t val ocamldoc : Tests.t + +val asmgen : Tests.t diff --git a/ocamltest/ocaml_variables.ml b/ocamltest/ocaml_variables.ml index 0374d21a5a..41bc206249 100644 --- a/ocamltest/ocaml_variables.ml +++ b/ocamltest/ocaml_variables.ml @@ -32,6 +32,9 @@ let all_modules = make ("all_modules", let binary_modules = make ("binary_modules", "Additional binary modules to link") +let bytecc_libs = make ("bytecc_libs", + "Libraries to link with for bytecode") + let c_preprocessor = make ("c_preprocessor", "Command to use to invoke the C preprocessor") @@ -80,14 +83,9 @@ let compiler_stdin = make ("compiler_stdin", let compile_only = make ("compile_only", "Compile only (do not link)") -let objext = make ("objext", - "Extension of object files") - -let ocamlc_flags = make ("ocamlc_flags", - "Flags passed to ocamlc.byte and ocamlc.opt") +let csc = make ("csc", "Path to the CSharp compiler") -let ocamlc_default_flags = make ("ocamlc_default_flags", - "Flags passed by default to ocamlc.byte and ocamlc.opt") +let csc_flags = make ("csc_flags", "Flags for the CSharp compiler") let directories = make ("directories", "Directories to include by all the compilers") @@ -95,15 +93,47 @@ let directories = make ("directories", let flags = make ("flags", "Flags passed to all the compilers") +let last_flags = make ("last_flags", + "Flags passed to all the compilers at the end of the commandline") + let libraries = make ("libraries", "Libraries the program should be linked with") +let mkdll = make ("mkdll", + "Command to use to build a DLL") + +let mkexe = make ("mkexe", + "Command used to build an executable program DLL") + let module_ = make ("module", "Compile one module at once") let modules = make ("modules", "Other modules of the test") +let nativecc_libs = make ("nativecc_libs", + "Libraries to link with for native code") + +let objext = make ("objext", + "Extension of object files") + +let ocamlc_byte = make ("ocamlc_byte", + "Path of the ocamlc.byte executable") + +let ocamlopt_byte = make ("ocamlopt_byte", + "Path of the ocamlopt.byte executable") + +let ocamlrun = make ("ocamlrun", + "Path of the ocamlrun executable") + +let ocamlc_flags = make ("ocamlc_flags", + "Flags passed to ocamlc.byte and ocamlc.opt") + +let ocamlc_default_flags = make ("ocamlc_default_flags", + "Flags passed by default to ocamlc.byte and ocamlc.opt") + + + let ocamllex_flags = make ("ocamllex_flags", "Flags passed to ocamllex") @@ -178,6 +208,14 @@ let ocaml_script_as_argument = let plugins = Variables.make ( "plugins", "plugins for ocamlc,ocamlopt or ocamldoc" ) +let shared_library_cflags = + Variables.make ("shared_library_cflags", + "Flags used to compile C files for inclusion in shared libraries") + +let sharedobjext = + Variables.make ("sharedobjext", + "Extension of shared object files") + let use_runtime = Variables.make ( "use_runtime", "Whether the -use-runtime option should be used" ) @@ -185,6 +223,7 @@ let _ = List.iter register_variable [ all_modules; binary_modules; + bytecc_libs; c_preprocessor; caml_ld_library_path; compare_programs; @@ -196,12 +235,20 @@ let _ = List.iter register_variable compiler_output2; compiler_stdin; compile_only; + csc; + csc_flags; directories; flags; + last_flags; libraries; + mkdll; module_; modules; + nativecc_libs; objext; + ocamlc_byte; + ocamlopt_byte; + ocamlrun; ocamlc_flags; ocamlc_default_flags; ocamlopt_flags; @@ -213,7 +260,6 @@ let _ = List.iter register_variable ocamlc_opt_exit_status; ocamlopt_opt_exit_status; ocamlrunparam; - os_type; ocamllex_flags; ocamlyacc_flags; ocamldoc_flags; @@ -224,6 +270,9 @@ let _ = List.iter register_variable ocamldebug_flags; ocamldebug_script; ocaml_script_as_argument; + os_type; plugins; + shared_library_cflags; + sharedobjext; use_runtime; ] diff --git a/ocamltest/ocaml_variables.mli b/ocamltest/ocaml_variables.mli index 18bbcc0bc4..5bf3d8687e 100644 --- a/ocamltest/ocaml_variables.mli +++ b/ocamltest/ocaml_variables.mli @@ -21,6 +21,9 @@ val all_modules : Variables.t val binary_modules : Variables.t +val bytecc_libs : Variables.t +(** Libraries to link with for bytecode *) + val c_preprocessor : Variables.t val caml_ld_library_path : Variables.t @@ -43,18 +46,37 @@ val compiler_stdin : Variables.t val compile_only : Variables.t +val csc : Variables.t + +val csc_flags : Variables.t + val directories : Variables.t val flags : Variables.t +val last_flags : Variables.t + val libraries : Variables.t +val mkdll : Variables.t +(** Command used to make a DLL *) + +val mkexe : Variables.t +(** Command used to build an executable program *) + val module_ : Variables.t val modules : Variables.t +val nativecc_libs : Variables.t +(** Libraries to link with for native code *) + val objext : Variables.t +val ocamlc_byte : Variables.t +val ocamlopt_byte : Variables.t +val ocamlrun : Variables.t + val ocamlc_flags : Variables.t val ocamlc_default_flags : Variables.t @@ -95,6 +117,10 @@ val ocamldoc_reference : Variables.t val ocaml_script_as_argument : Variables.t -val plugins: Variables.t +val plugins : Variables.t + +val shared_library_cflags : Variables.t + +val sharedobjext : Variables.t val use_runtime : Variables.t diff --git a/ocamltest/ocamltest_config.ml.in b/ocamltest/ocamltest_config.ml.in index ab0c7ead6a..887c469988 100644 --- a/ocamltest/ocamltest_config.ml.in +++ b/ocamltest/ocamltest_config.ml.in @@ -19,6 +19,14 @@ let arch = "@@ARCH@@" let afl_instrument = @@AFL_INSTRUMENT@@ +let asm = "@@ASM@@" + +let cc = "@@CC@@" + +let cflags = "@@CFLAGS@@" + +let ccomptype = "@@CCOMPTYPE@@" + let shared_libraries = @@SHARED_LIBRARIES@@ let libunix = @@UNIX@@ @@ -44,4 +52,21 @@ let flat_float_array = @@FLAT_FLOAT_ARRAY@@ let ocamldoc = @@OCAMLDOC@@ -let ocamldebug = @@OCAMLDOC@@ +let ocamldebug = @@OCAMLDEBUG@@ + +let native_dynlink = @@NATIVE_DYNLINK@@ + +let shared_library_cflags = "@@SHARED_LIBRARY_CFLAGS@@" + +let sharedobjext = "@@SHAREDOBJEXT@@" + +let csc = "@@CSC@@" + +let csc_flags = "@@CSCFLAGS@@" + +let mkdll = "@@MKDLL@@" +let mkexe = "@@MKEXE@@" + +let bytecc_libs = "@@BYTECCLIBS@@" + +let nativecc_libs = "@@NATIVECCLIBS@@" diff --git a/ocamltest/ocamltest_config.mli b/ocamltest/ocamltest_config.mli index d4aa6ca0b2..de2bd5a2ee 100644 --- a/ocamltest/ocamltest_config.mli +++ b/ocamltest/ocamltest_config.mli @@ -21,6 +21,18 @@ val arch : string val afl_instrument : bool (** Whether AFL support has been enabled in the compiler *) +val asm : string +(** Path to the assembler*) + +val cc : string +(** Path to the C compiler*) + +val cflags : string +(** Flags to pass to the C compiler *) + +val ccomptype : string +(** Type of C compiler (msvc, cc, etc.) *) + val shared_libraries : bool (** [true] if shared libraries are supported, [false] otherwise *) @@ -62,3 +74,25 @@ val ocamldoc : bool val ocamldebug : bool (** Whether ocamldebug has been enabled at configure time *) + +val native_dynlink : bool +(** Whether support for native dynlink is available or not *) + +val shared_library_cflags : string +(** Flags to use when compiling a C object for a shared library *) + +val sharedobjext : string +(** Extension of shared object files *) + +val csc : string +(** Path of the CSharp compiler, empty if not available *) + +val csc_flags : string +(** Flags for the CSharp compiler *) + +val mkdll : string +val mkexe : string + +val bytecc_libs : string + +val nativecc_libs : string diff --git a/ocamltest/run_win32.c b/ocamltest/run_win32.c index cd9e25128f..f53535754b 100644 --- a/ocamltest/run_win32.c +++ b/ocamltest/run_win32.c @@ -256,9 +256,16 @@ int run_command(const command_settings *settings) LPCWSTR current_directory = NULL; STARTUPINFO startup_info; PROCESS_INFORMATION process_info; - DWORD wait_result, status; + BOOL wait_result; + DWORD status, stamp, cur; DWORD timeout = (settings->timeout > 0) ? settings->timeout * 1000 : INFINITE; + JOBOBJECT_ASSOCIATE_COMPLETION_PORT port = {NULL, NULL}; + HANDLE hJob = NULL; + DWORD completion_code; + ULONG_PTR completion_key; + LPOVERLAPPED pOverlapped; + ZeroMemory(&startup_info, sizeof(STARTUPINFO)); startup_info.cb = sizeof(STARTUPINFO); startup_info.dwFlags = STARTF_USESTDHANDLES; @@ -328,7 +335,7 @@ int run_command(const command_settings *settings) NULL, /* SECURITY_ATTRIBUTES process_attributes */ NULL, /* SECURITY_ATTRIBUTES thread_attributes */ TRUE, /* BOOL inherit_handles */ - CREATE_UNICODE_ENVIRONMENT, /* DWORD creation_flags */ + CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT, /* DWORD creation_flags */ environment, NULL, /* LPCSTR current_directory */ &startup_info, @@ -336,23 +343,52 @@ int run_command(const command_settings *settings) ); checkerr( (! process_created), "CreateProcess failed", NULL); - CloseHandle(process_info.hThread); /* Not needed so closed ASAP */ - - wait_result = WaitForSingleObject(process_info.hProcess, timeout); - if (wait_result == WAIT_OBJECT_0) + hJob = CreateJobObject(NULL, NULL); + checkerr( (hJob == NULL), "CreateJobObject failed", NULL); + checkerr( !AssignProcessToJobObject(hJob, process_info.hProcess), + "AssignProcessToJob failed", NULL); + port.CompletionPort = + CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0); + checkerr( (port.CompletionPort == NULL), + "CreateIoCompletionPort failed", NULL); + checkerr( !SetInformationJobObject( + hJob, + JobObjectAssociateCompletionPortInformation, + &port, sizeof(port)), "SetInformationJobObject failed", NULL); + + ResumeThread(process_info.hThread); + CloseHandle(process_info.hThread); + + stamp = GetTickCount(); + while ((wait_result = GetQueuedCompletionStatus(port.CompletionPort, + &completion_code, + &completion_key, + &pOverlapped, + timeout)) + && completion_code != JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO) + { + if (timeout != INFINITE) + { + cur = GetTickCount(); + stamp = (cur > stamp ? cur - stamp : MAXDWORD - stamp + cur); + timeout = (timeout > stamp ? timeout - stamp : 0); + stamp = cur; + } + } + if (wait_result) { /* The child has terminated before the timeout has expired */ checkerr( (! GetExitCodeProcess(process_info.hProcess, &status)), "GetExitCodeProcess failed", NULL); - } else if (wait_result == WAIT_TIMEOUT) { + } else if (pOverlapped == NULL) { /* The timeout has expired, terminate the process */ - checkerr( (! TerminateProcess(process_info.hProcess, 0)), - "TerminateProcess failed", NULL); + checkerr( (! TerminateJobObject(hJob, 0)), + "TerminateJob failed", NULL); status = -1; wait_again = 1; } else { error_with_location(__FILE__, __LINE__, settings, - "WaitForSingleObject failed\n"); + "GetQueuedCompletionStatus failed\n"); report_error(__FILE__, __LINE__, settings, "Failure while waiting for process termination", NULL); status = -1; @@ -370,5 +406,7 @@ cleanup: WaitForSingleObject(process_info.hProcess, 1000); } if (process_created) CloseHandle(process_info.hProcess); + if (hJob != NULL) CloseHandle(hJob); + if (port.CompletionPort != NULL) CloseHandle(port.CompletionPort); return status; } diff --git a/parsing/ast_helper.ml b/parsing/ast_helper.ml index 2c28493395..f8fb81e9b0 100644 --- a/parsing/ast_helper.ml +++ b/parsing/ast_helper.ml @@ -515,6 +515,12 @@ module Te = struct ptyext_attributes = add_docs_attrs docs attrs; } + let mk_exception ?(attrs = []) ?(docs = empty_docs) constructor = + { + ptyexn_constructor = constructor; + ptyexn_attributes = add_docs_attrs docs attrs; + } + let constructor ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs) ?(info = empty_info) name kind = { diff --git a/parsing/ast_helper.mli b/parsing/ast_helper.mli index efc1dfcad5..42a1a57f42 100644 --- a/parsing/ast_helper.mli +++ b/parsing/ast_helper.mli @@ -206,6 +206,9 @@ module Te: ?params:(core_type * variance) list -> ?priv:private_flag -> lid -> extension_constructor list -> type_extension + val mk_exception: ?attrs:attrs -> ?docs:docs -> + extension_constructor -> type_exception + val constructor: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?info:info -> str -> extension_constructor_kind -> extension_constructor @@ -261,7 +264,7 @@ module Sig: val value: ?loc:loc -> value_description -> signature_item val type_: ?loc:loc -> rec_flag -> type_declaration list -> signature_item val type_extension: ?loc:loc -> type_extension -> signature_item - val exception_: ?loc:loc -> extension_constructor -> signature_item + val exception_: ?loc:loc -> type_exception -> signature_item val module_: ?loc:loc -> module_declaration -> signature_item val rec_module: ?loc:loc -> module_declaration list -> signature_item val modtype: ?loc:loc -> module_type_declaration -> signature_item @@ -284,7 +287,7 @@ module Str: val primitive: ?loc:loc -> value_description -> structure_item val type_: ?loc:loc -> rec_flag -> type_declaration list -> structure_item val type_extension: ?loc:loc -> type_extension -> structure_item - val exception_: ?loc:loc -> extension_constructor -> structure_item + val exception_: ?loc:loc -> type_exception -> structure_item val module_: ?loc:loc -> module_binding -> structure_item val rec_module: ?loc:loc -> module_binding list -> structure_item val modtype: ?loc:loc -> module_type_declaration -> structure_item diff --git a/parsing/ast_iterator.ml b/parsing/ast_iterator.ml index aa601e6419..080bde0f8c 100755 --- a/parsing/ast_iterator.ml +++ b/parsing/ast_iterator.ml @@ -61,6 +61,7 @@ type iterator = { typ: iterator -> core_type -> unit; type_declaration: iterator -> type_declaration -> unit; type_extension: iterator -> type_extension -> unit; + type_exception: iterator -> type_exception -> unit; type_kind: iterator -> type_kind -> unit; value_binding: iterator -> value_binding -> unit; value_description: iterator -> value_description -> unit; @@ -155,6 +156,10 @@ module T = struct List.iter (iter_fst (sub.typ sub)) ptyext_params; sub.attributes sub ptyext_attributes + let iter_type_exception sub {ptyexn_constructor; ptyexn_attributes} = + sub.extension_constructor sub ptyexn_constructor; + sub.attributes sub ptyexn_attributes + let iter_extension_constructor_kind sub = function Pext_decl(ctl, cto) -> iter_constructor_arguments sub ctl; iter_opt (sub.typ sub) cto @@ -243,7 +248,7 @@ module MT = struct | Psig_value vd -> sub.value_description sub vd | Psig_type (_rf, l) -> List.iter (sub.type_declaration sub) l | Psig_typext te -> sub.type_extension sub te - | Psig_exception ed -> sub.extension_constructor sub ed + | Psig_exception ed -> sub.type_exception sub ed | Psig_module x -> sub.module_declaration sub x | Psig_recmodule l -> List.iter (sub.module_declaration sub) l @@ -288,7 +293,7 @@ module M = struct | Pstr_primitive vd -> sub.value_description sub vd | Pstr_type (_rf, l) -> List.iter (sub.type_declaration sub) l | Pstr_typext te -> sub.type_extension sub te - | Pstr_exception ed -> sub.extension_constructor sub ed + | Pstr_exception ed -> sub.type_exception sub ed | Pstr_module x -> sub.module_binding sub x | Pstr_recmodule l -> List.iter (sub.module_binding sub) l | Pstr_modtype x -> sub.module_type_declaration sub x @@ -497,6 +502,7 @@ let default_iterator = type_kind = T.iter_type_kind; typ = T.iter; type_extension = T.iter_type_extension; + type_exception = T.iter_type_exception; extension_constructor = T.iter_extension_constructor; value_description = (fun this {pval_name; pval_type; pval_prim = _; pval_loc; diff --git a/parsing/ast_iterator.mli b/parsing/ast_iterator.mli index bd8e081687..0f06139d3f 100755 --- a/parsing/ast_iterator.mli +++ b/parsing/ast_iterator.mli @@ -58,6 +58,7 @@ type iterator = { typ: iterator -> core_type -> unit; type_declaration: iterator -> type_declaration -> unit; type_extension: iterator -> type_extension -> unit; + type_exception: iterator -> type_exception -> unit; type_kind: iterator -> type_kind -> unit; value_binding: iterator -> value_binding -> unit; value_description: iterator -> value_description -> unit; diff --git a/parsing/ast_mapper.ml b/parsing/ast_mapper.ml index 783d0e2eea..af2b62a6a9 100644 --- a/parsing/ast_mapper.ml +++ b/parsing/ast_mapper.ml @@ -66,6 +66,7 @@ type mapper = { typ: mapper -> core_type -> core_type; type_declaration: mapper -> type_declaration -> type_declaration; type_extension: mapper -> type_extension -> type_extension; + type_exception: mapper -> type_exception -> type_exception; type_kind: mapper -> type_kind -> type_kind; value_binding: mapper -> value_binding -> value_binding; value_description: mapper -> value_description -> value_description; @@ -162,6 +163,11 @@ module T = struct ~priv:ptyext_private ~attrs:(sub.attributes sub ptyext_attributes) + let map_type_exception sub {ptyexn_constructor; ptyexn_attributes} = + Te.mk_exception + (sub.extension_constructor sub ptyexn_constructor) + ~attrs:(sub.attributes sub ptyexn_attributes) + let map_extension_constructor_kind sub = function Pext_decl(ctl, cto) -> Pext_decl(map_constructor_arguments sub ctl, map_opt (sub.typ sub) cto) @@ -258,7 +264,7 @@ module MT = struct | Psig_value vd -> value ~loc (sub.value_description sub vd) | Psig_type (rf, l) -> type_ ~loc rf (List.map (sub.type_declaration sub) l) | Psig_typext te -> type_extension ~loc (sub.type_extension sub te) - | Psig_exception ed -> exception_ ~loc (sub.extension_constructor sub ed) + | Psig_exception ed -> exception_ ~loc (sub.type_exception sub ed) | Psig_module x -> module_ ~loc (sub.module_declaration sub x) | Psig_recmodule l -> rec_module ~loc (List.map (sub.module_declaration sub) l) @@ -306,7 +312,7 @@ module M = struct | Pstr_primitive vd -> primitive ~loc (sub.value_description sub vd) | Pstr_type (rf, l) -> type_ ~loc rf (List.map (sub.type_declaration sub) l) | Pstr_typext te -> type_extension ~loc (sub.type_extension sub te) - | Pstr_exception ed -> exception_ ~loc (sub.extension_constructor sub ed) + | Pstr_exception ed -> exception_ ~loc (sub.type_exception sub ed) | Pstr_module x -> module_ ~loc (sub.module_binding sub x) | Pstr_recmodule l -> rec_module ~loc (List.map (sub.module_binding sub) l) | Pstr_modtype x -> modtype ~loc (sub.module_type_declaration sub x) @@ -528,6 +534,7 @@ let default_mapper = type_kind = T.map_type_kind; typ = T.map; type_extension = T.map_type_extension; + type_exception = T.map_type_exception; extension_constructor = T.map_extension_constructor; value_description = (fun this {pval_name; pval_type; pval_prim; pval_loc; diff --git a/parsing/ast_mapper.mli b/parsing/ast_mapper.mli index 85b59e9c37..954e08e027 100644 --- a/parsing/ast_mapper.mli +++ b/parsing/ast_mapper.mli @@ -93,6 +93,7 @@ type mapper = { typ: mapper -> core_type -> core_type; type_declaration: mapper -> type_declaration -> type_declaration; type_extension: mapper -> type_extension -> type_extension; + type_exception: mapper -> type_exception -> type_exception; type_kind: mapper -> type_kind -> type_kind; value_binding: mapper -> value_binding -> value_binding; value_description: mapper -> value_description -> value_description; diff --git a/parsing/builtin_attributes.ml b/parsing/builtin_attributes.ml index a8eb33b607..57b5d4612d 100755 --- a/parsing/builtin_attributes.ml +++ b/parsing/builtin_attributes.ml @@ -62,11 +62,22 @@ let rec error_of_extension ext = let cat s1 s2 = if s2 = "" then s1 else s1 ^ "\n" ^ s2 -let rec deprecated_of_attrs = function +let deprecated_attr x = + match x with + | ({txt = "ocaml.deprecated"|"deprecated"; _},_) -> Some x + | _ -> None + +let rec deprecated_attrs = function | [] -> None - | ({txt = "ocaml.deprecated"|"deprecated"; _}, p) :: _ -> - Some (string_of_opt_payload p) - | _ :: tl -> deprecated_of_attrs tl + | hd :: tl -> + match deprecated_attr hd with + | Some x -> Some x + | None -> deprecated_attrs tl + +let deprecated_of_attrs l = + match deprecated_attrs l with + | None -> None + | Some (_,p) -> Some (string_of_opt_payload p) let check_deprecated loc attrs s = match deprecated_of_attrs attrs with @@ -117,6 +128,12 @@ let rec deprecated_of_str = function | _ -> None +let check_no_deprecated attrs = + match deprecated_attrs attrs with + | None -> () + | Some ({txt;loc},_) -> + Location.prerr_warning loc (Warnings.Misplaced_attribute txt) + let warning_attribute ?(ppwarning = true) = let process loc txt errflag payload = match string_of_payload payload with diff --git a/parsing/builtin_attributes.mli b/parsing/builtin_attributes.mli index 056316a697..be0de631a7 100755 --- a/parsing/builtin_attributes.mli +++ b/parsing/builtin_attributes.mli @@ -42,6 +42,8 @@ val check_deprecated_mutable_inclusion: def:Location.t -> use:Location.t -> Location.t -> Parsetree.attributes -> Parsetree.attributes -> string -> unit +val check_no_deprecated : Parsetree.attributes -> unit + val error_of_extension: Parsetree.extension -> Location.error val warning_attribute: ?ppwarning:bool -> Parsetree.attribute -> unit diff --git a/parsing/depend.ml b/parsing/depend.ml index 9e872fbc40..84cae99bef 100644 --- a/parsing/depend.ml +++ b/parsing/depend.ml @@ -160,6 +160,9 @@ let add_type_extension bv te = add bv te.ptyext_path; List.iter (add_extension_constructor bv) te.ptyext_constructors +let add_type_exception bv te = + add_extension_constructor bv te.ptyexn_constructor + let rec add_class_type bv cty = match cty.pcty_desc with Pcty_constr(l, tyl) -> @@ -350,8 +353,8 @@ and add_sig_item (bv, m) item = List.iter (add_type_declaration bv) dcls; (bv, m) | Psig_typext te -> add_type_extension bv te; (bv, m) - | Psig_exception pext -> - add_extension_constructor bv pext; (bv, m) + | Psig_exception te -> + add_type_exception bv te; (bv, m) | Psig_module pmd -> let m' = add_modtype_binding bv pmd.pmd_type in let add = StringMap.add pmd.pmd_name.txt m' in @@ -430,8 +433,9 @@ and add_struct_item (bv, m) item : _ StringMap.t * _ StringMap.t = | Pstr_typext te -> add_type_extension bv te; (bv, m) - | Pstr_exception pext -> - add_extension_constructor bv pext; (bv, m) + | Pstr_exception te -> + add_type_exception bv te; + (bv, m) | Pstr_module x -> let b = add_module_binding bv x.pmb_expr in let add = StringMap.add x.pmb_name.txt b in diff --git a/parsing/parser.mly b/parsing/parser.mly index 9ed25badac..6a6bb64b98 100644 --- a/parsing/parser.mly +++ b/parsing/parser.mly @@ -2045,18 +2045,20 @@ str_exception_declaration: | sig_exception_declaration { $1 } | EXCEPTION ext_attributes constr_ident EQUAL constr_longident attributes post_item_attributes - { let (ext,attrs) = $2 in - Te.rebind (mkrhs $3 3) (mkrhs $5 5) ~attrs:(attrs @ $6 @ $7) - ~loc:(symbol_rloc()) ~docs:(symbol_docs ()) - , ext } + { let (ext,attrs) = $2 in + Te.mk_exception ~attrs:$7 + (Te.rebind (mkrhs $3 3) (mkrhs $5 5) ~attrs:(attrs @ $6) + ~loc:(symbol_rloc()) ~docs:(symbol_docs ())) + , ext } ; sig_exception_declaration: | EXCEPTION ext_attributes constr_ident generalized_constructor_arguments attributes post_item_attributes { let args, res = $4 in let (ext,attrs) = $2 in - Te.decl (mkrhs $3 3) ~args ?res ~attrs:(attrs @ $5 @ $6) - ~loc:(symbol_rloc()) ~docs:(symbol_docs ()) + Te.mk_exception ~attrs:$6 + (Te.decl (mkrhs $3 3) ~args ?res ~attrs:(attrs @ $5) + ~loc:(symbol_rloc()) ~docs:(symbol_docs ())) , ext } ; let_exception_declaration: diff --git a/parsing/parsetree.mli b/parsing/parsetree.mli index 9f5de197b3..2302547f03 100644 --- a/parsing/parsetree.mli +++ b/parsing/parsetree.mli @@ -466,7 +466,14 @@ and extension_constructor = pext_kind : extension_constructor_kind; pext_loc : Location.t; pext_attributes: attributes; (* C of ... [@id1] [@id2] *) - } + } + +(* exception E *) +and type_exception = + { + ptyexn_constructor: extension_constructor; + ptyexn_attributes: attributes; (* ... [@@id1] [@@id2] *) + } and extension_constructor_kind = Pext_decl of constructor_arguments * core_type option @@ -691,7 +698,7 @@ and signature_item_desc = (* type t1 = ... and ... and tn = ... *) | Psig_typext of type_extension (* type t1 += ... *) - | Psig_exception of extension_constructor + | Psig_exception of type_exception (* exception C of T *) | Psig_module of module_declaration (* module X : MT *) @@ -818,7 +825,7 @@ and structure_item_desc = (* type t1 = ... and ... and tn = ... *) | Pstr_typext of type_extension (* type t1 += ... *) - | Pstr_exception of extension_constructor + | Pstr_exception of type_exception (* exception C of T exception C = M.X *) | Pstr_module of module_binding diff --git a/parsing/pprintast.ml b/parsing/pprintast.ml index e9e0de28e4..985c002c83 100644 --- a/parsing/pprintast.ml +++ b/parsing/pprintast.ml @@ -778,8 +778,9 @@ and extension ctxt f (s, e) = and item_extension ctxt f (s, e) = pp f "@[<2>[%%%%%s@ %a]@]" s.txt (payload ctxt) e -and exception_declaration ctxt f ext = - pp f "@[<hov2>exception@ %a@]" (extension_constructor ctxt) ext +and exception_declaration ctxt f x = + pp f "@[<hov2>exception@ %a@]%a" (extension_constructor ctxt) x.ptyexn_constructor + (item_attributes ctxt) x.ptyexn_attributes and class_signature ctxt f { pcsig_self = ct; pcsig_fields = l ;_} = let class_type_field f x = diff --git a/parsing/printast.ml b/parsing/printast.ml index 62ccc04b0a..df9ae8830b 100644 --- a/parsing/printast.ml +++ b/parsing/printast.ml @@ -448,6 +448,14 @@ and type_extension i ppf x = list (i+1) extension_constructor ppf x.ptyext_constructors; line i ppf "ptyext_private = %a\n" fmt_private_flag x.ptyext_private; +and type_exception i ppf x = + line i ppf "type_exception\n"; + attributes i ppf x.ptyexn_attributes; + let i = i+1 in + line i ppf "ptyext_constructor =\n"; + let i = i+1 in + extension_constructor i ppf x.ptyexn_constructor + and extension_constructor i ppf x = line i ppf "extension_constructor %a\n" fmt_location x.pext_loc; attributes i ppf x.pext_attributes; @@ -676,9 +684,9 @@ and signature_item i ppf x = | Psig_typext te -> line i ppf "Psig_typext\n"; type_extension i ppf te - | Psig_exception ext -> + | Psig_exception te -> line i ppf "Psig_exception\n"; - extension_constructor i ppf ext; + type_exception i ppf te | Psig_module pmd -> line i ppf "Psig_module %a\n" fmt_string_loc pmd.pmd_name; attributes i ppf pmd.pmd_attributes; @@ -784,9 +792,9 @@ and structure_item i ppf x = | Pstr_typext te -> line i ppf "Pstr_typext\n"; type_extension i ppf te - | Pstr_exception ext -> + | Pstr_exception te -> line i ppf "Pstr_exception\n"; - extension_constructor i ppf ext; + type_exception i ppf te | Pstr_module x -> line i ppf "Pstr_module\n"; module_binding i ppf x diff --git a/stdlib/Makefile b/stdlib/Makefile index ef7a8d4ff7..4b044914da 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -87,6 +87,13 @@ allopt-prof: stdlib.p.cmxa std_exit.p.cmx .PHONY: install install:: +# Transitional: when upgrading from 4.06 -> 4.07, module M is in stdlib__m.cm*, +# while previously it was in m.cm*, which confuses the compiler. + rm -f $(patsubst stdlib__%,"$(INSTALL_LIBDIR)/%", $(filter stdlib__%,$(OBJS))) +# Remove "old" pervasives.* and bigarray.* to avoid getting confused with the +# Stdlib versions. + rm -f "$(INSTALL_LIBDIR)/pervasives.*" "$(INSTALL_LIBDIR)/bigarray.*" +# End transitional $(INSTALL_DATA) \ stdlib.cma std_exit.cmo *.cmi *.cmt *.cmti *.mli *.ml camlheader_ur \ "$(INSTALL_LIBDIR)" diff --git a/stdlib/format.ml b/stdlib/format.ml index e02ffae1f2..2769313333 100644 --- a/stdlib/format.ml +++ b/stdlib/format.ml @@ -239,7 +239,7 @@ exception Empty_queue let peek_queue = function | { body = Cons { head = x; tail = _; }; _ } -> x - | { body = Nil; insert = _; } -> raise Empty_queue + | { body = Nil; insert = _; } -> raise_notrace Empty_queue let take_queue = function @@ -247,7 +247,7 @@ let take_queue = function q.body <- tl; if tl = Nil then q.insert <- Nil; (* Maintain the invariant. *) x - | { body = Nil; insert = _; } -> raise Empty_queue + | { body = Nil; insert = _; } -> raise_notrace Empty_queue (* Enter a token in the pretty-printer queue. *) @@ -393,7 +393,7 @@ let format_pp_token state size = function | Pp_tbox tabs :: _ -> let rec find n = function | x :: l -> if x >= n then x else find n l - | [] -> raise Not_found in + | [] -> raise_notrace Not_found in let tab = match !tabs with | x :: _ -> diff --git a/testsuite/Makefile b/testsuite/Makefile index 7375c4676c..f6bb0dcb02 100644 --- a/testsuite/Makefile +++ b/testsuite/Makefile @@ -50,7 +50,7 @@ ocamltest_program := $(or \ $(wildcard $(ocamltest_directory)/ocamltest.opt$(EXE)),\ $(wildcard $(ocamltest_directory)/ocamltest$(EXE))) -ocamltest := $(FLEXLINK_PREFIX) SORT=$(SORT) $(ocamltest_program) +ocamltest := $(FLEXLINK_PREFIX) SORT=$(SORT) MAKE=$(MAKE) $(ocamltest_program) .PHONY: default default: diff --git a/testsuite/makefiles/Makefile.common b/testsuite/makefiles/Makefile.common index 76063f7cac..dcb303285b 100644 --- a/testsuite/makefiles/Makefile.common +++ b/testsuite/makefiles/Makefile.common @@ -16,6 +16,8 @@ TOPDIR=$(BASEDIR)/.. include $(TOPDIR)/Makefile.tools +codegen := $(OTOPDIR)/testsuite/tools/codegen + .PHONY: defaultpromote defaultpromote: @for file in *.reference; do \ @@ -61,12 +63,10 @@ defaultclean: @$(OCAMLLEX) -q $< > /dev/null .cmm.s: - @$(OCAMLRUN) ./codegen -S $*.cmm + @$(OCAMLRUN) $(codegen) -S $*.cmm .cmm.obj: - @$(OCAMLRUN) ./codegen $*.cmm \ - | grep -v "_caml_\(young_ptr\|young_limit\|extra_params\ - \|allocN\|raise_exn\|reraise_exn\)" > $*.s + @$(OCAMLRUN) $(codegen) $*.cmm > $*.s @set -o pipefail ; \ $(ASM) $*.obj $*.s | tail -n +2 diff --git a/testsuite/tests/asmgen/Makefile b/testsuite/tests/asmgen/Makefile deleted file mode 100644 index f6d0c238ff..0000000000 --- a/testsuite/tests/asmgen/Makefile +++ /dev/null @@ -1,122 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. - -include $(BASEDIR)/../config/Makefile - -INCLUDES=\ - -I $(OTOPDIR)/parsing \ - -I $(OTOPDIR)/utils \ - -I $(OTOPDIR)/typing \ - -I $(OTOPDIR)/middle_end \ - -I $(OTOPDIR)/bytecomp \ - -I $(OTOPDIR)/asmcomp - -OTHEROBJS=\ - $(OTOPDIR)/compilerlibs/ocamlcommon.cma \ - $(OTOPDIR)/compilerlibs/ocamloptcomp.cma - -OBJS=parsecmmaux.cmo parsecmm.cmo lexcmm.cmo - -ADD_COMPFLAGS=$(INCLUDES) -w -40 -g - -default: - @if $(BYTECODE_ONLY) || $(SKIP) ; then $(MAKE) skips ; else \ - $(MAKE) all; \ - fi - -all: - @$(MAKE) arch codegen - @$(MAKE) tests - -main.cmo: parsecmm.cmo - -codegen: parsecmm.ml lexcmm.ml $(OBJS:.cmo=.cmi) $(OBJS) main.cmo - @$(OCAMLC) $(LINKFLAGS) -o codegen $(OTHEROBJS) $(OBJS) main.cmo - -parsecmm.mli parsecmm.ml: parsecmm.mly - @$(OCAMLYACC) -q parsecmm.mly - -lexcmm.ml: lexcmm.mll - @$(OCAMLLEX) -q lexcmm.mll - -CASES=fib tak quicksort quicksort2 soli \ - arith checkbound tagged-fib tagged-integr tagged-quicksort tagged-tak \ - catch-try catch-rec even-odd even-odd-spill pgcd -ARGS_fib=-DINT_INT -DFUN=fib main.c -ARGS_tak=-DUNIT_INT -DFUN=takmain main.c -ARGS_quicksort=-DSORT -DFUN=quicksort main.c -ARGS_quicksort2=-DSORT -DFUN=quicksort main.c -ARGS_soli=-DUNIT_INT -DFUN=solitaire main.c -ARGS_integr=-DINT_FLOAT -DFUN=test main.c -ARGS_arith=mainarith.c -ARGS_checkbound=-DCHECKBOUND main.c -ARGS_tagged-fib=-DINT_INT -DFUN=fib main.c -ARGS_tagged-integr=-DINT_FLOAT -DFUN=test main.c -ARGS_tagged-quicksort=-DSORT -DFUN=quicksort main.c -ARGS_tagged-tak=-DUNIT_INT -DFUN=takmain main.c -ARGS_catch-try=-DINT_INT -DFUN=catch_exit main.c -ARGS_catch-rec=-DINT_INT -DFUN=catch_fact main.c -ARGS_even-odd=-DINT_INT -DFUN=is_even main.c -ARGS_even-odd-spill=-DINT_INT -DFUN=is_even main.c -ARGS_pgcd=-DINT_INT -DFUN=pgcd_30030 main.c - -skips: - @for c in $(CASES); do \ - echo " ... testing '$$c': => skipped"; \ - done - -one: - @$(call CCOMP,$(NAME).out $(ARGS_$(NAME)) $(NAME).$(O) $(ARCH).$(O)) \ - && echo " => passed" || echo " => failed" - -clean: defaultclean - @rm -f ./codegen *.out *.out.manifest *.$(O) *.exe - @rm -f parsecmm.ml parsecmm.mli lexcmm.ml - @rm -f $(CASES:=.s) - -include $(BASEDIR)/makefiles/Makefile.common - -ifeq "$(CCOMPTYPE)-$(ARCH)" "msvc-amd64" -# these tests are not ported to MSVC64 yet -SKIP=true -else -SKIP=false -endif - -ifeq "$(WITH_SPACETIME)" "true" -# These tests have not been ported for Spacetime -SKIP=true -endif - -ifeq ($(CCOMPTYPE),msvc) -CCOMP=set -o pipefail ; $(CC) $(CFLAGS) /Fe$(1) | tail -n +2 -else -CCOMP=$(CC) $(CFLAGS) -o $(1) -endif -tests: $(CASES:=.$(O)) - @for c in $(CASES); do \ - printf " ... testing '$$c':"; \ - $(MAKE) one NAME=$$c; \ - done - -promote: - -arch: $(ARCH).$(O) - -i386.obj: i386nt.asm - @set -o pipefail ; \ - $(ASM) $@ $^ | tail -n +2 diff --git a/testsuite/tests/asmgen/arith.cmm b/testsuite/tests/asmgen/arith.cmm index 09156568a9..fad3f29f0a 100644 --- a/testsuite/tests/asmgen/arith.cmm +++ b/testsuite/tests/asmgen/arith.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "mainarith.c" +arguments = "mainarith.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/catch-rec.cmm b/testsuite/tests/asmgen/catch-rec.cmm index 69208f5f4a..a81a102478 100644 --- a/testsuite/tests/asmgen/catch-rec.cmm +++ b/testsuite/tests/asmgen/catch-rec.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DINT_INT -DFUN=catch_fact main.c" +* asmgen +*) + (function "catch_fact" (b:int) (catch (exit fact b 1) with (fact c acc) diff --git a/testsuite/tests/asmgen/catch-try.cmm b/testsuite/tests/asmgen/catch-try.cmm index bbbdc387b1..767f66f5c4 100644 --- a/testsuite/tests/asmgen/catch-try.cmm +++ b/testsuite/tests/asmgen/catch-try.cmm @@ -1,3 +1,8 @@ +(* TEST +files = "main.c" +arguments = "-DINT_INT -DFUN=catch_exit main.c" +* asmgen +*) (function "catch_exit" (b:int) (+ 33 diff --git a/testsuite/tests/asmgen/checkbound.cmm b/testsuite/tests/asmgen/checkbound.cmm index 35206f25bb..0b864d5b8c 100644 --- a/testsuite/tests/asmgen/checkbound.cmm +++ b/testsuite/tests/asmgen/checkbound.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DCHECKBOUND main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/even-odd-spill.cmm b/testsuite/tests/asmgen/even-odd-spill.cmm index 0c5f05589c..13aa3ab913 100644 --- a/testsuite/tests/asmgen/even-odd-spill.cmm +++ b/testsuite/tests/asmgen/even-odd-spill.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DINT_INT -DFUN=is_even main.c" +* asmgen +*) + ("format_odd": string "odd %d\n\000") ("format_even": string "even %d\n\000") diff --git a/testsuite/tests/asmgen/even-odd.cmm b/testsuite/tests/asmgen/even-odd.cmm index db79f1cab8..cef393c576 100644 --- a/testsuite/tests/asmgen/even-odd.cmm +++ b/testsuite/tests/asmgen/even-odd.cmm @@ -1,3 +1,9 @@ +(* TEST +files= "main.c" +arguments = "-DINT_INT -DFUN=is_even main.c" +* asmgen +*) + (function "is_even" (b:int) (catch (exit even b) with (odd v) diff --git a/testsuite/tests/asmgen/fib.cmm b/testsuite/tests/asmgen/fib.cmm index 49de4ba12e..c1a82de268 100644 --- a/testsuite/tests/asmgen/fib.cmm +++ b/testsuite/tests/asmgen/fib.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DINT_INT -DFUN=fib main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/integr.cmm b/testsuite/tests/asmgen/integr.cmm index c82d60b247..84a3895c24 100644 --- a/testsuite/tests/asmgen/integr.cmm +++ b/testsuite/tests/asmgen/integr.cmm @@ -1,3 +1,11 @@ +(* TEST +files = "main.c" +arguments = "-DINT_FLOAT -DFUN=test main.c" +* skip +reason = "This test is currently broken" +** asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/mainarith.c b/testsuite/tests/asmgen/mainarith.c index de876bfead..cdba6a9d20 100644 --- a/testsuite/tests/asmgen/mainarith.c +++ b/testsuite/tests/asmgen/mainarith.c @@ -19,7 +19,7 @@ #include <stdlib.h> #include <string.h> -#include "../../../byterun/caml/config.h" +#include <caml/config.h> #define FMT ARCH_INTNAT_PRINTF_FORMAT void caml_ml_array_bound_error(void) diff --git a/testsuite/tests/asmgen/ocamltests b/testsuite/tests/asmgen/ocamltests new file mode 100644 index 0000000000..0a2a435576 --- /dev/null +++ b/testsuite/tests/asmgen/ocamltests @@ -0,0 +1,17 @@ +arith.cmm +catch-rec.cmm +catch-try.cmm +checkbound.cmm +even-odd-spill.cmm +even-odd.cmm +fib.cmm +integr.cmm +pgcd.cmm +quicksort.cmm +quicksort2.cmm +soli.cmm +tagged-fib.cmm +tagged-integr.cmm +tagged-quicksort.cmm +tagged-tak.cmm +tak.cmm diff --git a/testsuite/tests/asmgen/pgcd.cmm b/testsuite/tests/asmgen/pgcd.cmm index e75a149ac0..c42724dd84 100644 --- a/testsuite/tests/asmgen/pgcd.cmm +++ b/testsuite/tests/asmgen/pgcd.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DINT_INT -DFUN=pgcd_30030 main.c" +* asmgen +*) + (function "pgcd_30030" (a:int) (catch (exit pgcd a 30030) with (pgcd n m) diff --git a/testsuite/tests/asmgen/quicksort.cmm b/testsuite/tests/asmgen/quicksort.cmm index b08594154b..7779780f3d 100644 --- a/testsuite/tests/asmgen/quicksort.cmm +++ b/testsuite/tests/asmgen/quicksort.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DSORT -DFUN=quicksort main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/quicksort2.cmm b/testsuite/tests/asmgen/quicksort2.cmm index 96c1fc12e7..2c6b278e82 100644 --- a/testsuite/tests/asmgen/quicksort2.cmm +++ b/testsuite/tests/asmgen/quicksort2.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DSORT -DFUN=quicksort main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/soli.cmm b/testsuite/tests/asmgen/soli.cmm index c8ffc5d684..cd0822b14e 100644 --- a/testsuite/tests/asmgen/soli.cmm +++ b/testsuite/tests/asmgen/soli.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DUNIT_INT -DFUN=solitaire main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/tagged-fib.cmm b/testsuite/tests/asmgen/tagged-fib.cmm index d83afaa487..b9b96152de 100644 --- a/testsuite/tests/asmgen/tagged-fib.cmm +++ b/testsuite/tests/asmgen/tagged-fib.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DINT_INT -DFUN=fib main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/tagged-integr.cmm b/testsuite/tests/asmgen/tagged-integr.cmm index b89bd50863..c2781efe1d 100644 --- a/testsuite/tests/asmgen/tagged-integr.cmm +++ b/testsuite/tests/asmgen/tagged-integr.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DINT_FLOAT -DFUN=test main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/tagged-quicksort.cmm b/testsuite/tests/asmgen/tagged-quicksort.cmm index 59293aa2ed..7c2ce6ef82 100644 --- a/testsuite/tests/asmgen/tagged-quicksort.cmm +++ b/testsuite/tests/asmgen/tagged-quicksort.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DSORT -DFUN=quicksort main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/tagged-tak.cmm b/testsuite/tests/asmgen/tagged-tak.cmm index 30c98a00bf..3ff6ea4f2e 100644 --- a/testsuite/tests/asmgen/tagged-tak.cmm +++ b/testsuite/tests/asmgen/tagged-tak.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DUNIT_INT -DFUN=takmain main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/asmgen/tak.cmm b/testsuite/tests/asmgen/tak.cmm index 2750fff334..1835ef66a5 100644 --- a/testsuite/tests/asmgen/tak.cmm +++ b/testsuite/tests/asmgen/tak.cmm @@ -1,3 +1,9 @@ +(* TEST +files = "main.c" +arguments = "-DUNIT_INT -DFUN=takmain main.c" +* asmgen +*) + (**************************************************************************) (* *) (* OCaml *) diff --git a/testsuite/tests/lib-bigarray-2/Makefile b/testsuite/tests/lib-bigarray-2/Makefile deleted file mode 100644 index f36a3f0056..0000000000 --- a/testsuite/tests/lib-bigarray-2/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. -LIBRARIES=unix bigarray -C_FILES=bigarrfstub -F_FILES=bigarrf -ADD_COMPFLAGS=-I $(OTOPDIR)/otherlibs/bigarray \ - -I $(OTOPDIR)/otherlibs/$(UNIXLIB) - -include $(BASEDIR)/makefiles/Makefile.several -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/lib-bigarray-2/bigarrfml.ml b/testsuite/tests/lib-bigarray-2/bigarrfml.ml index d33862edd5..bcdeefa46c 100644 --- a/testsuite/tests/lib-bigarray-2/bigarrfml.ml +++ b/testsuite/tests/lib-bigarray-2/bigarrfml.ml @@ -1,3 +1,33 @@ +(* TEST + +files = "bigarrf.f bigarrfstub.c" +last_flags = "-cclib -lgfortran" + +* script +script = "sh ${test_source_directory}/gfortran-available" + +** setup-ocamlc.byte-build-env +*** script +script = "gfortran -c bigarrf.f" +**** ocamlc.byte +all_modules = "bigarrf.o bigarrfstub.c bigarrfml.ml" +***** run +output = "${test_build_directory}/program-output" +stdout = "${output}" +****** check-program-output + +** setup-ocamlopt.byte-build-env +*** script +script = "gfortran -c bigarrf.f" +**** ocamlopt.byte +all_modules = "bigarrf.o bigarrfstub.c bigarrfml.ml" +***** run +output = "${test_build_directory}/program-output" +stdout = "${output}" +****** check-program-output + +*) + open Bigarray open Printf diff --git a/testsuite/tests/lib-bigarray-2/bigarrfstub.c b/testsuite/tests/lib-bigarray-2/bigarrfstub.c index efec26aa48..1f9a2dce28 100644 --- a/testsuite/tests/lib-bigarray-2/bigarrfstub.c +++ b/testsuite/tests/lib-bigarray-2/bigarrfstub.c @@ -15,7 +15,7 @@ #include <stdio.h> #include <caml/mlvalues.h> -#include <bigarray.h> +#include <caml/bigarray.h> extern void filltab_(void); extern void printtab_(float * data, int * dimx, int * dimy); diff --git a/testsuite/tests/lib-bigarray-2/gfortran-available b/testsuite/tests/lib-bigarray-2/gfortran-available new file mode 100644 index 0000000000..7a7a94c424 --- /dev/null +++ b/testsuite/tests/lib-bigarray-2/gfortran-available @@ -0,0 +1,9 @@ +#!/bin/sh +if ! which gfortran > /dev/null 2>&1; then + echo "gfortran not available" > ${ocamltest_response} + test_result=${TEST_SKIP} +else + test_result=${TEST_PASS} +fi + +exit ${test_result} diff --git a/testsuite/tests/lib-bigarray-2/ocamltests b/testsuite/tests/lib-bigarray-2/ocamltests new file mode 100644 index 0000000000..133f99d674 --- /dev/null +++ b/testsuite/tests/lib-bigarray-2/ocamltests @@ -0,0 +1 @@ +bigarrfml.ml diff --git a/testsuite/tests/lib-dynlink-csharp/Makefile b/testsuite/tests/lib-dynlink-csharp/Makefile deleted file mode 100644 index a385d1caf1..0000000000 --- a/testsuite/tests/lib-dynlink-csharp/Makefile +++ /dev/null @@ -1,122 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. -# Only run this test for TOOLCHAIN=msvc -CSC_COMMAND=$(filter csc,$(subst msvc,csc,$(TOOLCHAIN))) -CSC=$(CSC_COMMAND) $(CSC_FLAGS) - -COMPFLAGS=-I $(OTOPDIR)/otherlibs/bigarray -I $(OTOPDIR)/otherlibs/dynlink \ - -I $(OTOPDIR)/byterun -LD_PATH=$(TOPDIR)/otherlibs/win32unix:$(TOPDIR)/otherlibs/bigarray:$(TOPDIR)/otherlibs/dynlink - -default: - @$(SET_LD_PATH) $(MAKE) all - -.PHONY: all -all: prepare bytecode bytecode-dll native native-dll - -.PHONY: prepare -prepare: - @if $(SUPPORTS_SHARED_LIBRARIES); then \ - $(OCAMLC) -c plugin.ml && \ - if $(BYTECODE_ONLY) ; then : ; else \ - $(OCAMLOPT) -o plugin.cmxs -shared plugin.ml; \ - fi; \ - fi - -.PHONY: bytecode -bytecode: - @printf " ... testing 'bytecode':" - @if ! $(SUPPORTS_SHARED_LIBRARIES) || ! which $(CSC_COMMAND) >/dev/null 2>&1; \ - then \ - echo " => skipped"; \ - else \ - rm -f main.exe main.dll; \ - $(OCAMLC) -output-obj -o main.dll dynlink.cma main.ml entry.c; \ - $(CSC) /nologo /nowarn:1668 /out:main.exe main.cs; \ - ./main.exe > bytecode.result; \ - $(DIFF) bytecode.reference bytecode.result >/dev/null \ - && echo " => passed" || echo " => failed"; \ - fi - -.PHONY: bytecode-dll -bytecode-dll: - @printf " ... testing 'bytecode-dll':" - @if ! $(SUPPORTS_SHARED_LIBRARIES) || ! which $(CSC_COMMAND) > /dev/null 2>&1; \ - then \ - echo " => skipped"; \ - else \ - rm -f main.exe main_obj.$(O) main.dll; \ - $(OCAMLC) -output-obj -o main_obj.$(O) dynlink.cma entry.c main.ml; \ - $(MKDLL) -maindll -o main.dll main_obj.$(O) entry.$(O) \ - $(CTOPDIR)/byterun/libcamlrun.$(A) $(BYTECCLIBS); \ - $(CSC) /nologo /nowarn:1668 /out:main.exe main.cs; \ - ./main.exe >bytecode-dll.result; \ - $(DIFF) bytecode.reference bytecode-dll.result >/dev/null \ - && echo " => passed" || echo " => failed"; \ - fi - -.PHONY: native -native: - @printf " ... testing 'native':" - @if ! $(SUPPORTS_SHARED_LIBRARIES) || $(BYTECODE_ONLY) \ - || ! which $(CSC_COMMAND) > /dev/null 2>&1; then \ - echo " => skipped"; \ - else \ - rm -f main.exe main.dll; \ - $(OCAMLOPT) -output-obj -o main.dll dynlink.cmxa entry.c main.ml; \ - $(CSC) /nologo /nowarn:1668 /out:main.exe main.cs; \ - ./main.exe > native.result; \ - $(DIFF) native.reference native.result > /dev/null \ - && echo " => passed" || echo " => failed"; \ - fi - -.PHONY: native-dll -native-dll: - @printf " ... testing 'native-dll':" - @if ! $(SUPPORTS_SHARED_LIBRARIES) || $(BYTECODE_ONLY) \ - || ! which $(CSC_COMMAND) > /dev/null 2>&1; then \ - echo " => skipped"; \ - else \ - rm -f main.exe main_obj.$(O) main.dll; \ - $(OCAMLOPT) -output-obj -o main_obj.$(O) dynlink.cmxa entry.c \ - main.ml; \ - $(MKDLL) -maindll -o main.dll main_obj.$(O) entry.$(O) \ - $(CTOPDIR)/asmrun/libasmrun.lib $(NATIVECCLIBS); \ - $(CSC) /nologo /nowarn:1668 /out:main.exe main.cs; \ - ./main.exe > native-dll.result; \ - $(DIFF) native.reference native-dll.result >/dev/null \ - && echo " => passed" || echo " => failed"; \ - fi - -.PHONY: promote -promote: defaultpromote - -.PHONY: clean -clean: defaultclean - @rm -f *.result *.exe *.dll *.so *.obj *.o - -include $(BASEDIR)/makefiles/Makefile.common - -ifneq ($(FLEXLINK_PREFIX),) -MKDLL=$(WINTOPDIR)/boot/ocamlrun $(WINTOPDIR)/flexdll/flexlink.exe $(FLEXLINK_FLAGS) -endif - -ifeq ($(HOST),msvc) -CSC_FLAGS=/platform:x86 -else -CSC_FLAGS= -endif diff --git a/testsuite/tests/lib-dynlink-csharp/bytecode.reference b/testsuite/tests/lib-dynlink-csharp/bytecode.reference deleted file mode 100644 index 1c61c156e7..0000000000 --- a/testsuite/tests/lib-dynlink-csharp/bytecode.reference +++ /dev/null @@ -1,7 +0,0 @@ -Now starting the OCaml engine. -Main is running. -Loading ../../../otherlibs/win32unix/unix.cma -Loading ../../../otherlibs/bigarray/bigarray.cma -Loading plugin.cmo -I'm the plugin. -OK. diff --git a/testsuite/tests/lib-dynlink-csharp/entry.c b/testsuite/tests/lib-dynlink-csharp/entry.c index 12e39a5b75..12e39a5b75 100755..100644 --- a/testsuite/tests/lib-dynlink-csharp/entry.c +++ b/testsuite/tests/lib-dynlink-csharp/entry.c diff --git a/testsuite/tests/lib-dynlink-csharp/main.bytecode.reference b/testsuite/tests/lib-dynlink-csharp/main.bytecode.reference new file mode 100644 index 0000000000..c162cac001 --- /dev/null +++ b/testsuite/tests/lib-dynlink-csharp/main.bytecode.reference @@ -0,0 +1,5 @@ +Now starting the OCaml engine. +Main is running. +Loading plugin.cmo +I'm the plugin. +OK. diff --git a/testsuite/tests/lib-dynlink-csharp/main.cs b/testsuite/tests/lib-dynlink-csharp/main.cs index 5cbb8e8689..5cbb8e8689 100755..100644 --- a/testsuite/tests/lib-dynlink-csharp/main.cs +++ b/testsuite/tests/lib-dynlink-csharp/main.cs diff --git a/testsuite/tests/lib-dynlink-csharp/main.ml b/testsuite/tests/lib-dynlink-csharp/main.ml index 93fe830ce5..eaa2135100 100755..100644 --- a/testsuite/tests/lib-dynlink-csharp/main.ml +++ b/testsuite/tests/lib-dynlink-csharp/main.ml @@ -1,3 +1,83 @@ +(* TEST + +include dynlink + +files = "entry.c main.cs plugin.ml" + +* csharp-compiler +** shared-libraries +set csharp_cmd = "${csc} ${csc_flags} /out:main.exe main.cs" + +*** setup-ocamlc.byte-build-env +**** ocamlc.byte +module = "plugin.ml" +***** ocamlc.byte +module = "" +flags = "-output-obj" +program = "main.dll" +all_modules = "dynlink.cma main.ml entry.c" +****** script +script = "${csharp_cmd}" +******* run +program = "./main.exe" +******** check-program-output +reference = "${test_source_directory}/main.bytecode.reference" + +*** setup-ocamlc.byte-build-env +compiler_directory_suffix = "-dll" +**** ocamlc.byte +module = "plugin.ml" +***** ocamlc.byte +module = "" +flags = "-output-obj" +program = "main_obj.${objext}" +all_modules = "dynlink.cma entry.c main.ml" +****** script +script = "${mkdll} -maindll -o main.dll main_obj.${objext} entry.${objext} ${ocamlsrcdir}/byterun/libcamlrun.lib ${bytecc_libs}" +******* script +script = "${csharp_cmd}" +******** run +program = "./main.exe" +********* check-program-output +reference = "${test_source_directory}/main.bytecode.reference" + +*** setup-ocamlopt.byte-build-env +**** ocamlopt.byte +program = "plugin.cmxs" +flags = "-shared" +all_modules = "plugin.ml" +***** ocamlopt.byte +flags = "-output-obj" +program= "main.dll" +all_modules = "dynlink.cmxa entry.c main.ml" +****** script +script = "${csharp_cmd}" +******* run +program = "./main.exe" +******** check-program-output +reference = "${test_source_directory}/main.native.reference" + +*** setup-ocamlopt.byte-build-env +compiler_directory_suffix = "-dll" +**** ocamlopt.byte +program = "plugin.cmxs" +flags = "-shared" +all_modules = "plugin.ml" +***** ocamlopt.byte +flags = "-output-obj" +program = "main_obj.${objext}" +all_modules = "dynlink.cmxa entry.c main.ml" +****** script +script = "${mkdll} -maindll -o main.dll main_obj.${objext} entry.${objext} ${ocamlsrcdir}/asmrun/libasmrun.lib ${nativecc_libs}" +******* script +script = "${csharp_cmd}" +******** run +program = "./main.exe" +********* check-program-output +reference = "${test_source_directory}/main.native.reference" + +*) + let load s = Printf.printf "Loading %s\n%!" s; try @@ -14,12 +94,6 @@ let () = print_endline "Main is running."; Dynlink.init (); Dynlink.allow_unsafe_modules true; - let s1,s2,s3 = - Dynlink.adapt_filename "../../../otherlibs/win32unix/unix.cma", - Dynlink.adapt_filename "../../../otherlibs/bigarray/bigarray.cma", - Dynlink.adapt_filename "plugin.cmo" - in - load s1; - load s2; - load s3; + let plugin_name = Dynlink.adapt_filename "plugin.cmo" in + load plugin_name; print_endline "OK." diff --git a/testsuite/tests/lib-dynlink-csharp/main.native.reference b/testsuite/tests/lib-dynlink-csharp/main.native.reference new file mode 100644 index 0000000000..a26525eea8 --- /dev/null +++ b/testsuite/tests/lib-dynlink-csharp/main.native.reference @@ -0,0 +1,5 @@ +Now starting the OCaml engine. +Main is running. +Loading plugin.cmxs +I'm the plugin. +OK. diff --git a/testsuite/tests/lib-dynlink-csharp/native.reference b/testsuite/tests/lib-dynlink-csharp/native.reference deleted file mode 100644 index cfb612da6d..0000000000 --- a/testsuite/tests/lib-dynlink-csharp/native.reference +++ /dev/null @@ -1,7 +0,0 @@ -Now starting the OCaml engine. -Main is running. -Loading ../../../otherlibs/win32unix/unix.cmxs -Loading ../../../otherlibs/bigarray/bigarray.cmxs -Loading plugin.cmxs -I'm the plugin. -OK. diff --git a/testsuite/tests/lib-dynlink-csharp/ocamltests b/testsuite/tests/lib-dynlink-csharp/ocamltests new file mode 100644 index 0000000000..d389d15661 --- /dev/null +++ b/testsuite/tests/lib-dynlink-csharp/ocamltests @@ -0,0 +1 @@ +main.ml diff --git a/testsuite/tests/lib-dynlink-csharp/plugin.ml b/testsuite/tests/lib-dynlink-csharp/plugin.ml index aacf9f21bc..aacf9f21bc 100755..100644 --- a/testsuite/tests/lib-dynlink-csharp/plugin.ml +++ b/testsuite/tests/lib-dynlink-csharp/plugin.ml diff --git a/testsuite/tests/lib-dynlink-native/Makefile b/testsuite/tests/lib-dynlink-native/Makefile deleted file mode 100644 index 50ed0e8b87..0000000000 --- a/testsuite/tests/lib-dynlink-native/Makefile +++ /dev/null @@ -1,126 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=$(shell pwd)/../.. - -COMPFLAGS=-I $(OTOPDIR)/otherlibs/$(UNIXLIBVAR)unix \ - -I $(OTOPDIR)/otherlibs/systhreads \ - -I $(OTOPDIR)/otherlibs/dynlink -LD_PATH = $(TOPDIR)/otherlibs/$(UNIXLIBVAR)unix:$(TOPDIR)/otherlibs/systhreads\ -:$(TOPDIR)/otherlibs/dynlink - -.PHONY: default -default: - @if ! $(NATDYNLINK) || $(BYTECODE_ONLY) ; then \ - echo " ... testing 'main' => skipped"; \ - else \ - $(SET_LD_PATH) $(MAKE) all; \ - fi - -.PHONY: all -all: compile run - -PLUGINS=plugin.so plugin2.so sub/plugin.so sub/plugin3.so plugin4.so \ - mypack.so packed1.so packed1_client.so pack_client.so plugin_ref.so \ - plugin_high_arity.so plugin_ext.so plugin_simple.so bug.so \ - plugin_thread.so plugin4_unix.so a.so b.so c.so - -.PHONY: compile -compile: $(PLUGINS) main$(EXE) mylib.so - -.PHONY: run -run: - @printf " ... testing 'main'" - @./main$(EXE) plugin.so plugin2.so plugin_thread.so > result - @$(DIFF) reference result >/dev/null \ - && echo " => passed" || echo " => failed" - -main$(EXE): api.cmx main.cmx - @$(OCAMLOPT) -I +threads -o main$(EXE) -linkall unix.cmxa threads.cmxa \ - dynlink.cmxa api.cmx main.cmx - -main_ext$(EXE): api.cmx main.cmx factorial.$(O) - @$(OCAMLOPT) -o main_ext$(EXE) dynlink.cmxa api.cmx main.cmx \ - factorial.$(O) - -sub/plugin3.cmx: sub/api.cmi sub/api.cmx sub/plugin3.ml - @cd sub; \ - mv api.cmx api.cmx.bak; \ - $(OCAMLOPT) -c plugin3.ml; \ - mv api.cmx.bak api.cmx - -plugin2.cmx: api.cmx plugin.cmi plugin.cmx - @mv plugin.cmx plugin.cmx.bak; - @$(OCAMLOPT) -c plugin2.ml - @mv plugin.cmx.bak plugin.cmx - -sub/api.so: sub/api.cmi sub/api.ml - @cd sub; $(OCAMLOPT) -c $(SUPPORTS_SHARED_LIBRARIES) api.ml - -sub/api.cmi: sub/api.mli - @cd sub; $(OCAMLOPT) -c -opaque api.mli - -sub/api.cmx: sub/api.cmi sub/api.ml - @cd sub; $(OCAMLOPT) -c api.ml - -plugin.cmi: plugin.mli - @$(OCAMLOPT) -c -opaque plugin.mli - -plugin.cmx: api.cmx plugin.cmi -sub/plugin.cmx: api.cmx -plugin4.cmx: api.cmx -main.cmx: api.cmx -plugin_ext.cmx: api.cmx plugin_ext.ml - @$(OCAMLOPT) -c plugin_ext.ml - -plugin_ext.so: factorial.$(O) plugin_ext.cmx - @$(OCAMLOPT) -shared -o plugin_ext.so factorial.$(O) \ - plugin_ext.cmx - -plugin4_unix.so: plugin4.cmx - @$(OCAMLOPT) -shared -o plugin4_unix.so unix.cmxa plugin4.cmx - -packed1_client.cmx: packed1.cmx - -pack_client.cmx: mypack.cmx - -packed1.cmx: api.cmx packed1.ml - @$(OCAMLOPT) -c $(COMPFLAGS) -for-pack Mypack packed1.ml - -mypack.cmx: packed1.cmx - @$(OCAMLOPT) $(COMPFLAGS) -S -pack -o mypack.cmx packed1.cmx - -mylib.cmxa: plugin.cmx plugin2.cmx - @$(OCAMLOPT) $(COMPFLAGS) -a -o mylib.cmxa plugin.cmx plugin2.cmx - -factorial.$(O): factorial.c - @$(OCAMLOPT) -c -ccopt "$(SHAREDCCCOMPOPTS)" -ccopt -I \ - -ccopt $(CTOPDIR)/byterun \ - factorial.c - -.PHONY: promote -promote: - @cp result reference - -.PRECIOUS: %.cmx - -.PHONY: clean -clean: defaultclean - @rm -f result *.so *.o *.cm* main main_ext *.exe *.s *.asm *.obj - @rm -f *.a *.lib - @rm -f sub/*.so sub/*.o sub/*.cm* sub/*.s sub/*.asm sub/*.obj - @rm -f marshal.data - -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/lib-dynlink-native/a.ml b/testsuite/tests/lib-dynlink-native/a.ml index b79158225f..b79158225f 100755..100644 --- a/testsuite/tests/lib-dynlink-native/a.ml +++ b/testsuite/tests/lib-dynlink-native/a.ml diff --git a/testsuite/tests/lib-dynlink-native/b.ml b/testsuite/tests/lib-dynlink-native/b.ml index afa1bef051..afa1bef051 100755..100644 --- a/testsuite/tests/lib-dynlink-native/b.ml +++ b/testsuite/tests/lib-dynlink-native/b.ml diff --git a/testsuite/tests/lib-dynlink-native/c.ml b/testsuite/tests/lib-dynlink-native/c.ml index d4de70f40a..d4de70f40a 100755..100644 --- a/testsuite/tests/lib-dynlink-native/c.ml +++ b/testsuite/tests/lib-dynlink-native/c.ml diff --git a/testsuite/tests/lib-dynlink-native/main.ml b/testsuite/tests/lib-dynlink-native/main.ml index 8c738aeb70..f64c0071c7 100644 --- a/testsuite/tests/lib-dynlink-native/main.ml +++ b/testsuite/tests/lib-dynlink-native/main.ml @@ -1,3 +1,212 @@ +(* TEST + +files = "a.ml api.ml b.ml bug.ml c.ml factorial.c pack_client.ml packed1_client.ml packed1.ml plugin2.ml plugin4.ml plugin_ext.ml plugin_high_arity.ml plugin.ml plugin.mli plugin_ref.ml plugin_simple.ml plugin_thread.ml" + +include systhreads +include dynlink + +set subdir = "${test_source_directory}/sub" + +* native-dynlink +libraries = "" (* We will add them manually where appropriated *) +** setup-ocamlopt.byte-build-env +ocamlopt_default_flags = "" (* Removes the -ccopt -no-pie on ised on OpenBSD *) +*** script +script = "mkdir sub" +**** script +script = "cp ${subdir}/api.mli ${subdir}/api.ml ${subdir}/plugin3.ml ${subdir}/plugin.ml sub" +***** ocamlopt.byte +module = "api.ml" +****** ocamlopt.byte +flags = "-opaque" +module = "plugin.mli" +******* ocamlopt.byte +flags = "" +module = "plugin.ml" +******** ocamlopt.byte +module= "" +flags = "-shared" +program = "plugin.so" +all_modules = "plugin.cmx" +********* script +script = "mv plugin.cmx plugin.cmx.bak" +********** ocamlopt.byte +flags = "" +module = "plugin2.ml" +*********** script +script = "mv plugin.cmx.bak plugin.cmx" +************ ocamlopt.byte +module= "" +flags = "-shared" +program = "plugin2.so" +all_modules = "plugin2.cmx" +************* ocamlopt.byte +flags = "" +module = "sub/plugin.ml" +************** ocamlopt.byte +module = "" +flags = "-shared" +program = "sub/plugin.so" +all_modules = "sub/plugin.cmx" +*************** cd +cwd = "sub" +**************** ocamlopt.byte +module = "api.mli" +flags = "-opaque" +***************** ocamlopt.byte +flags = "" +module = "api.ml" +****************** script +script = "mv api.cmx api.cmx.bak" +******************* ocamlopt.byte +module = "plugin3.ml" +******************** script +script = "mv api.cmx.bak api.cmx" +********************* cd +cwd = ".." +********************** ocamlopt.byte +module = "" +flags = "-shared" +program = "sub/plugin3.so" +all_modules = "sub/plugin3.cmx" +*********************** ocamlopt.byte +flags = "" +module = "plugin4.ml" +************************ ocamlopt.byte +module = "" +flags = "-shared" +program = "plugin4.so" +all_modules = "plugin4.cmx" +************************* ocamlopt.byte +module = "packed1.ml" +flags = "-for-pack Mypack" +************************** ocamlopt.byte +flags = "-S -pack" +module = "" +program = "mypack.cmx" +all_modules = "packed1.cmx" +*************************** ocamlopt.byte +program = "mypack.so" +flags = "-shared" +all_modules = "mypack.cmx" +**************************** ocamlopt.byte +program = "packed1.so" +flags = "-shared" +all_modules = "packed1.cmx" +***************************** ocamlopt.byte +flags = "" +module = "packed1_client.ml" +****************************** ocamlopt.byte +module = "" +program = "packed1_client.so" +flags = "-shared" +all_modules = "packed1_client.cmx" +******************************* ocamlopt.byte +flags = "" +module = "pack_client.ml" +******************************** ocamlopt.byte +module = "" +program = "pack_client.so" +flags = "-shared" +all_modules = "pack_client.cmx" +********************************* ocamlopt.byte +flags = "" +module = "plugin_ref.ml" +********************************** ocamlopt.byte +module = "" +program = "plugin_ref.so" +flags = "-shared" +all_modules = "plugin_ref.cmx" +*********************************** ocamlopt.byte +flags = "" +module = "plugin_high_arity.ml" +************************************ ocamlopt.byte +module = "" +program = "plugin_high_arity.so" +flags = "-shared" +all_modules = "plugin_high_arity.cmx" +************************************* ocamlopt.byte +flags = "-ccopt ${shared_library_cflags}" +module = "factorial.c" +************************************** ocamlopt.byte +flags = "" +module = "plugin_ext.ml" +*************************************** ocamlopt.byte +module = "" +program = "plugin_ext.so" +flags = "-shared" +all_modules = "factorial.${objext} plugin_ext.cmx" +**************************************** ocamlopt.byte +module = "plugin_simple.ml" +flags = "" +***************************************** ocamlopt.byte +module = "" +program = "plugin_simple.so" +flags = "-shared" +all_modules = "plugin_simple.cmx" +***************************************** ocamlopt.byte +module = "bug.ml" +flags = "" +****************************************** ocamlopt.byte +module = "" +program = "bug.so" +flags = "-shared" +all_modules = "bug.cmx" +****************************************** ocamlopt.byte +module = "plugin_thread.ml" +flags = "" +******************************************* ocamlopt.byte +module = "" +program = "plugin_thread.so" +flags = "-shared" +all_modules = "plugin_thread.cmx" +******************************************** ocamlopt.byte +program = "plugin4_unix.so" +all_modules = "unix.cmxa plugin4.cmx" +********************************************* ocamlopt.byte +flags = "" +compile_only = "true" +all_modules = "a.ml b.ml c.ml main.ml" +********************************************** ocamlopt.byte +module = "" +compile_only = "false" +flags = "-shared" +program = "a.so" +all_modules = "a.cmx" +*********************************************** ocamlopt.byte +program = "b.so" +all_modules = "b.cmx" +************************************************ ocamlopt.byte +program = "c.so" +all_modules = "c.cmx" +************************************************* ocamlopt.byte +program = "mylib.cmxa" +flags = "-a" +all_modules = "plugin.cmx plugin2.cmx" +************************************************** ocamlopt.byte +program = "mylib.so" +flags = "-shared -linkall" +all_modules = "mylib.cmxa" +*************************************************** ocamlopt.byte +program = "${test_build_directory}/main.exe" +libraries = "unix threads dynlink" +flags = "-linkall" +all_modules = "api.cmx main.cmx" +(* +On OpenBSD, the compiler produces warnings like +/usr/bin/ld: warning: creating a DT_TEXTREL in a shared object. +So the compiler output is not empty on OpenBSD so an emptiness check +would fail on this platform. + +We thus do not check compiler output. This was not done either before the +test was ported to ocamltest. +*) + +**************************************************** run +arguments = "plugin.so plugin2.so plugin_thread.so" +***************************************************** check-program-output +*) + let () = Api.add_cb (fun () -> print_endline "Callback from main") diff --git a/testsuite/tests/lib-dynlink-native/reference b/testsuite/tests/lib-dynlink-native/main.reference index e9e4ee45dd..e9e4ee45dd 100644 --- a/testsuite/tests/lib-dynlink-native/reference +++ b/testsuite/tests/lib-dynlink-native/main.reference diff --git a/testsuite/tests/lib-dynlink-native/ocamltests b/testsuite/tests/lib-dynlink-native/ocamltests new file mode 100644 index 0000000000..d389d15661 --- /dev/null +++ b/testsuite/tests/lib-dynlink-native/ocamltests @@ -0,0 +1 @@ +main.ml diff --git a/testsuite/tests/output-complete-obj/ocamltests b/testsuite/tests/output-complete-obj/ocamltests new file mode 100644 index 0000000000..31c13b4431 --- /dev/null +++ b/testsuite/tests/output-complete-obj/ocamltests @@ -0,0 +1 @@ +test.ml diff --git a/testsuite/tests/output-complete-obj/test.ml b/testsuite/tests/output-complete-obj/test.ml new file mode 100644 index 0000000000..2e650986af --- /dev/null +++ b/testsuite/tests/output-complete-obj/test.ml @@ -0,0 +1,34 @@ +(* TEST + +files = "test.ml_stub.c" + +* libunix +** setup-ocamlc.byte-build-env +*** ocamlc.byte +flags = "-w a -output-complete-obj" +program = "test.ml.bc.${objext}" +**** script +script = "${mkexe} -I${ocamlsrcdir}/byterun -o test.ml_bc_stub.exe test.ml.bc.${objext} ${nativecc_libs} test.ml_stub.c" +output = "${compiler_output}" +***** run +program = "./test.ml_bc_stub.exe" +stdout = "program-output" +stderr = "program-output" + +* skip +reason = "native test disabled until -output-complete-obj gets fixed" +** setup-ocamlopt.byte-build-env +*** ocamlopt.byte +flags = "-w a -output-complete-obj" +program = "test.ml.exe.${objext}" +**** script +script = "${mkexe} -I${ocamlsrcdir}/byterun -o test.ml_stub.exe test.ml.exe.${objext} ${bytecc_libs} test.ml_stub.c" +output = "${compiler_output}" +***** run +program = "./test.ml_stub.exe" +stdout = "program-output" +stderr = "program-output" + +*) + +let () = Printf.printf "Test!!\n%!" diff --git a/testsuite/tests/output_obj/test.ml_stub.c b/testsuite/tests/output-complete-obj/test.ml_stub.c index c3e8d3f352..c3e8d3f352 100644 --- a/testsuite/tests/output_obj/test.ml_stub.c +++ b/testsuite/tests/output-complete-obj/test.ml_stub.c diff --git a/testsuite/tests/output_obj/Makefile.disabled b/testsuite/tests/output_obj/Makefile.disabled deleted file mode 100644 index 17fb689f43..0000000000 --- a/testsuite/tests/output_obj/Makefile.disabled +++ /dev/null @@ -1,58 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. -SHOULD_FAIL= - - -compile: - @for file in *.ml; do \ - printf " ... testing '$$file' with native"; \ - if $(BYTECODE_ONLY); then \ - echo " => skipped"; \ - else \ - rm -f log $${file}.exe.$(O) $${file}_stub$(EXE); \ - ( set -x; \ - $(OCAMLOPT) -w a -output-complete-obj -o $${file}.exe.$(O) \ - $${file} && \ - $(MKEXE) -I$(CTOPDIR)/byterun -o $${file}_stub$(EXE) \ - $${file}.exe.$(O) $(NATIVECCLIBS) $${file}_stub.c && \ - ./$${file}_stub$(EXE) ) > log 2>&1 \ - && echo " => passed" || (echo " => failed" && cat log); \ - fi \ - done - @for file in *.ml; do \ - printf " ... testing '$$file' with byte"; \ - if [ $(TOOLCHAIN) = msvc ]; then \ - echo " => skipped"; \ - else \ - rm -f log $${file}.bc.$(O) $${file}_bc_stub$(EXE); \ - ( set -x; \ - $(OCAMLC) -ccopt "-I$(CTOPDIR)/byterun" -w a -output-complete-obj\ - -o $${file}.bc.$(O) $${file} && \ - $(MKEXE) -I$(CTOPDIR)/byterun -o $${file}_bc_stub$(EXE) \ - $${file}.bc.$(O) $(BYTECCLIBS) $${file}_stub.c && \ - ./$${file}_bc_stub$(EXE) ) > log 2>&1 \ - && echo " => passed" || (echo " => failed" && cat log); \ - fi; \ - done - @rm -f log - -promote: - -clean: defaultclean - @rm -f ./a.out - -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/output_obj/test.ml b/testsuite/tests/output_obj/test.ml deleted file mode 100644 index 2cdc201d65..0000000000 --- a/testsuite/tests/output_obj/test.ml +++ /dev/null @@ -1 +0,0 @@ -let () = Printf.printf "Test!!\n%!" diff --git a/testsuite/tests/parsing/attributes.compilers.reference b/testsuite/tests/parsing/attributes.compilers.reference index bc3967be20..f77ea26b57 100644 --- a/testsuite/tests/parsing/attributes.compilers.reference +++ b/testsuite/tests/parsing/attributes.compilers.reference @@ -1,34 +1,68 @@ [ - structure_item (attributes.ml[8,120+0]..[8,120+8]) + structure_item (attributes.ml[8,120+0]..[8,120+28]) + Pstr_exception + type_exception + attribute "foo" + [] + ptyext_constructor = + extension_constructor (attributes.ml[8,120+0]..[8,120+28]) + attribute "foo" + [] + pext_name = "Foo" + pext_kind = + Pext_decl + [] + None + structure_item (attributes.ml[10,150+0]..[10,150+44]) + Pstr_exception + type_exception + attribute "foo" + [] + ptyext_constructor = + extension_constructor (attributes.ml[10,150+0]..[10,150+44]) + attribute "foo" + [] + pext_name = "Bar" + pext_kind = + Pext_decl + [ + core_type (attributes.ml[10,150+18]..[10,150+21]) + attribute "foo" + [] + Ptyp_constr "int" (attributes.ml[10,150+18]..[10,150+21]) + [] + ] + None + structure_item (attributes.ml[12,196+0]..[12,196+8]) Pstr_attribute "foo" [] - structure_item (attributes.ml[10,130+0]..[11,169+9]) + structure_item (attributes.ml[14,206+0]..[15,245+9]) Pstr_value Nonrec [ <def> attribute "foo" [] - pattern (attributes.ml[10,130+4]..[10,130+38]) ghost + pattern (attributes.ml[14,206+4]..[14,206+38]) ghost Ppat_constraint - pattern (attributes.ml[10,130+4]..[10,130+13]) + pattern (attributes.ml[14,206+4]..[14,206+13]) attribute "foo" [] - Ppat_var "x" (attributes.ml[10,130+5]..[10,130+6]) - core_type (attributes.ml[10,130+16]..[10,130+20]) + Ppat_var "x" (attributes.ml[14,206+5]..[14,206+6]) + core_type (attributes.ml[14,206+16]..[14,206+20]) attribute "foo" [] - Ptyp_constr "unit" (attributes.ml[10,130+16]..[10,130+20]) + Ptyp_constr "unit" (attributes.ml[14,206+16]..[14,206+20]) [] - expression (attributes.ml[10,130+30]..[10,130+32]) + expression (attributes.ml[14,206+30]..[14,206+32]) attribute "foo" [] - Pexp_construct "()" (attributes.ml[10,130+30]..[10,130+32]) + Pexp_construct "()" (attributes.ml[14,206+30]..[14,206+32]) None ] - structure_item (attributes.ml[13,180+0]..[15,217+7]) + structure_item (attributes.ml[17,256+0]..[19,293+7]) Pstr_type Rec [ - type_declaration "t" (attributes.ml[13,180+5]..[13,180+6]) (attributes.ml[13,180+0]..[15,217+7]) + type_declaration "t" (attributes.ml[17,256+5]..[17,256+6]) (attributes.ml[17,256+0]..[19,293+7]) attribute "foo" [] ptype_params = @@ -38,15 +72,15 @@ ptype_kind = Ptype_variant [ - (attributes.ml[14,189+2]..[14,189+27]) - "Foo" (attributes.ml[14,189+4]..[14,189+7]) + (attributes.ml[18,265+2]..[18,265+27]) + "Foo" (attributes.ml[18,265+4]..[18,265+7]) attribute "foo" [] [ - core_type (attributes.ml[14,189+12]..[14,189+13]) + core_type (attributes.ml[18,265+12]..[18,265+13]) attribute "foo" [] - Ptyp_constr "t" (attributes.ml[14,189+12]..[14,189+13]) + Ptyp_constr "t" (attributes.ml[18,265+12]..[18,265+13]) [] ] None @@ -55,23 +89,23 @@ ptype_manifest = None ] - structure_item (attributes.ml[17,226+0]..[17,226+8]) + structure_item (attributes.ml[21,302+0]..[21,302+8]) Pstr_attribute "foo" [] - structure_item (attributes.ml[20,237+0]..[29,344+7]) + structure_item (attributes.ml[24,313+0]..[33,420+7]) Pstr_module - "M" (attributes.ml[20,237+7]..[20,237+8]) + "M" (attributes.ml[24,313+7]..[24,313+8]) attribute "foo" [] - module_expr (attributes.ml[20,237+11]..[28,334+3]) + module_expr (attributes.ml[24,313+11]..[32,410+3]) attribute "foo" [] Pmod_structure [ - structure_item (attributes.ml[21,255+2]..[25,310+11]) + structure_item (attributes.ml[25,331+2]..[29,386+11]) Pstr_type Rec [ - type_declaration "t" (attributes.ml[21,255+7]..[21,255+8]) (attributes.ml[21,255+2]..[25,310+11]) + type_declaration "t" (attributes.ml[25,331+7]..[25,331+8]) (attributes.ml[25,331+2]..[29,386+11]) attribute "foo" [] attribute "foo" @@ -83,50 +117,70 @@ ptype_kind = Ptype_record [ - (attributes.ml[22,268+4]..[22,268+25]) + (attributes.ml[26,344+4]..[26,344+25]) attribute "foo" [] Immutable - "l" (attributes.ml[22,268+4]..[22,268+5]) core_type (attributes.ml[22,268+9]..[22,268+10]) + "l" (attributes.ml[26,344+4]..[26,344+5]) core_type (attributes.ml[26,344+9]..[26,344+10]) attribute "foo" [] - Ptyp_constr "t" (attributes.ml[22,268+9]..[22,268+10]) + Ptyp_constr "t" (attributes.ml[26,344+9]..[26,344+10]) [] ] ptype_private = Public ptype_manifest = None ] - structure_item (attributes.ml[27,323+2]..[27,323+10]) + structure_item (attributes.ml[31,399+2]..[31,399+10]) Pstr_attribute "foo" [] ] - structure_item (attributes.ml[31,353+0]..[39,477+7]) - Pstr_modtype "S" (attributes.ml[31,353+12]..[31,353+13]) + structure_item (attributes.ml[35,429+0]..[45,601+7]) + Pstr_modtype "S" (attributes.ml[35,429+12]..[35,429+13]) attribute "foo" [] - module_type (attributes.ml[31,353+16]..[38,467+3]) + module_type (attributes.ml[35,429+16]..[44,591+3]) attribute "foo" [] Pmty_signature [ - signature_item (attributes.ml[33,374+2]..[34,442+11]) + signature_item (attributes.ml[37,450+2]..[37,450+46]) + Psig_exception + type_exception + attribute "foo" + [] + ptyext_constructor = + extension_constructor (attributes.ml[37,450+2]..[37,450+46]) + attribute "foo" + [] + pext_name = "Bar" + pext_kind = + Pext_decl + [ + core_type (attributes.ml[37,450+20]..[37,450+23]) + attribute "foo" + [] + Ptyp_constr "int" (attributes.ml[37,450+20]..[37,450+23]) + [] + ] + None + signature_item (attributes.ml[39,498+2]..[40,566+11]) Psig_include - module_type (attributes.ml[33,374+10]..[33,374+61]) + module_type (attributes.ml[39,498+10]..[39,498+61]) attribute "foo" [] Pmty_with - module_type (attributes.ml[33,374+11]..[33,374+35]) + module_type (attributes.ml[39,498+11]..[39,498+35]) attribute "foo" [] Pmty_typeof - module_expr (attributes.ml[33,374+27]..[33,374+28]) + module_expr (attributes.ml[39,498+27]..[39,498+28]) attribute "foo" [] - Pmod_ident "M" (attributes.ml[33,374+27]..[33,374+28]) + Pmod_ident "M" (attributes.ml[39,498+27]..[39,498+28]) [ - Pwith_typesubst "t" (attributes.ml[33,374+53]..[33,374+54]) - type_declaration "t" (attributes.ml[33,374+53]..[33,374+54]) (attributes.ml[33,374+48]..[33,374+61]) + Pwith_typesubst "t" (attributes.ml[39,498+53]..[39,498+54]) + type_declaration "t" (attributes.ml[39,498+53]..[39,498+54]) (attributes.ml[39,498+48]..[39,498+61]) ptype_params = [] ptype_cstrs = @@ -136,17 +190,17 @@ ptype_private = Public ptype_manifest = Some - core_type (attributes.ml[33,374+58]..[33,374+61]) - Ptyp_constr "M.t" (attributes.ml[33,374+58]..[33,374+61]) + core_type (attributes.ml[39,498+58]..[39,498+61]) + Ptyp_constr "M.t" (attributes.ml[39,498+58]..[39,498+61]) [] ] attribute "foo" [] - signature_item (attributes.ml[36,455+2]..[36,455+10]) + signature_item (attributes.ml[42,579+2]..[42,579+10]) Psig_attribute "foo" [] ] - structure_item (attributes.ml[41,486+0]..[41,486+8]) + structure_item (attributes.ml[47,610+0]..[47,610+8]) Pstr_attribute "foo" [] ] diff --git a/testsuite/tests/parsing/attributes.ml b/testsuite/tests/parsing/attributes.ml index 8bee64d670..b89df9ca86 100644 --- a/testsuite/tests/parsing/attributes.ml +++ b/testsuite/tests/parsing/attributes.ml @@ -5,6 +5,10 @@ *** check-ocamlc.byte-output *) +exception Foo [@foo] [@@foo] + +exception Bar of (int [@foo]) [@foo] [@@foo] + [@@@foo] let (x[@foo]) : unit [@foo] = ()[@foo] @@ -30,6 +34,8 @@ end[@foo] module type S = sig + exception Bar of (int [@foo]) [@foo] [@@foo] + include (module type of (M[@foo]))[@foo] with type t := M.t[@foo] [@@foo] diff --git a/testsuite/tests/parsing/shortcut_ext_attr.compilers.reference b/testsuite/tests/parsing/shortcut_ext_attr.compilers.reference index d8ceb058b2..c4c64593a9 100644 --- a/testsuite/tests/parsing/shortcut_ext_attr.compilers.reference +++ b/testsuite/tests/parsing/shortcut_ext_attr.compilers.reference @@ -687,14 +687,16 @@ [ structure_item (shortcut_ext_attr.ml[86,1759+0]..[86,1759+21]) Pstr_exception - extension_constructor (shortcut_ext_attr.ml[86,1759+0]..[86,1759+21]) - attribute "foo" - [] - pext_name = "X" - pext_kind = - Pext_decl - [] - None + type_exception + ptyext_constructor = + extension_constructor (shortcut_ext_attr.ml[86,1759+0]..[86,1759+21]) + attribute "foo" + [] + pext_name = "X" + pext_kind = + Pext_decl + [] + None ] structure_item (shortcut_ext_attr.ml[88,1782+0]..[88,1782+22]) ghost Pstr_extension "foo" @@ -858,14 +860,16 @@ [ signature_item (shortcut_ext_attr.ml[105,2091+2]..[105,2091+23]) Psig_exception - extension_constructor (shortcut_ext_attr.ml[105,2091+2]..[105,2091+23]) - attribute "foo" - [] - pext_name = "X" - pext_kind = - Pext_decl - [] - None + type_exception + ptyext_constructor = + extension_constructor (shortcut_ext_attr.ml[105,2091+2]..[105,2091+23]) + attribute "foo" + [] + pext_name = "X" + pext_kind = + Pext_decl + [] + None ] signature_item (shortcut_ext_attr.ml[107,2116+2]..[107,2116+24]) ghost Psig_extension "foo" diff --git a/testsuite/tests/runtime-errors/Makefile b/testsuite/tests/runtime-errors/Makefile deleted file mode 100644 index b7f05895fb..0000000000 --- a/testsuite/tests/runtime-errors/Makefile +++ /dev/null @@ -1,80 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Xavier Clerc, SED, INRIA Rocquencourt * -#* * -#* Copyright 2010 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. - -.PHONY: default -default: - @$(MAKE) compile - @$(MAKE) run - -.PHONY: compile -compile: - @for f in *.ml; do \ - F=`basename $$f .ml`; \ - rm -f $$F.bytecode $$F.native $$F.native.exe; \ - $(OCAMLC) -w a -o $$F.bytecode $$f; \ - if $(BYTECODE_ONLY); then : ; else \ - $(OCAMLOPT) -w a -o $$F.native$(EXE) $$f; \ - fi; \ - done - $(if $(findstring win32,$(UNIX_OR_WIN32)),:, \ - @grep -q HAS_STACK_OVERFLOW_DETECTION $(TOPDIR)/byterun/caml/s.h \ - || rm -f stackoverflow.native$(EXE)) - -# Cygwin doesn't allow the stack limit to be changed - the 4096 is -# intended to be larger than the its default stack size. The logic -# causes the test to be skipped if the stacksize cannot be brought -# below this value (uname -s value exits with an error status in Cygwin) -.PHONY: run -run: - @ul=`ulimit -s`; \ - if ( [ "$$ul" = "unlimited" ] || [ $$ul -gt 4096 ] ) ; then \ - ulimit -s 1024 && ul=1 || ul=0 ; \ - else \ - ul=1; \ - fi; \ - for f in *.bytecode; do \ - printf " ... testing '$$f':"; \ - if [ $$ul -eq 1 ] ; then \ - $(OCAMLRUN) ./$$f >$$f.result 2>&1 || true; \ - DIFF="$(DIFF)" sh $$f.checker \ - && echo " => passed" || echo " => failed"; \ - else \ - echo " => unexpected error"; \ - fi; \ - fn=`basename $$f bytecode`native; \ - if $(BYTECODE_ONLY) || [ ! -f "$${fn}$(EXE)" ] ; then \ - echo " ... testing '$$fn': => skipped" ; \ - else \ - printf " ... testing '$$fn':"; \ - if [ $$ul -eq 1 ] ; then \ - ./$${fn}$(EXE) >$$fn.result 2>&1 || true; \ - DIFF="$(DIFF)" sh $$fn.checker \ - && echo " => passed" || echo " => failed"; \ - else \ - echo " => unexpected error"; \ - fi; \ - fi; \ - done - -.PHONY: promote -promote: defaultpromote - -.PHONY: clean -clean: defaultclean - @rm -f *.bytecode *.native *.native.exe *.result - -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/runtime-errors/has-stackoverflow-detection b/testsuite/tests/runtime-errors/has-stackoverflow-detection new file mode 100644 index 0000000000..240be643ee --- /dev/null +++ b/testsuite/tests/runtime-errors/has-stackoverflow-detection @@ -0,0 +1,8 @@ +#!/bin/sh +if grep -q HAS_STACK_OVERFLOW_DETECTION ${ocamlsrcdir}/byterun/caml/s.h; then + test_result=${TEST_PASS}; +else + test_result=${TEST_SKIP}; +fi + +exit ${test_result} diff --git a/testsuite/tests/runtime-errors/ocamltests b/testsuite/tests/runtime-errors/ocamltests new file mode 100644 index 0000000000..c4a51b5cb1 --- /dev/null +++ b/testsuite/tests/runtime-errors/ocamltests @@ -0,0 +1,2 @@ +stackoverflow.ml +syserror.ml diff --git a/testsuite/tests/runtime-errors/stackoverflow.bytecode.checker b/testsuite/tests/runtime-errors/stackoverflow.bytecode.checker deleted file mode 100644 index c850ba05a3..0000000000 --- a/testsuite/tests/runtime-errors/stackoverflow.bytecode.checker +++ /dev/null @@ -1,16 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Damien Doligez, projet Gallium, INRIA Rocquencourt * -#* * -#* Copyright 2013 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -$DIFF stackoverflow.bytecode.reference stackoverflow.bytecode.result diff --git a/testsuite/tests/runtime-errors/stackoverflow.ml b/testsuite/tests/runtime-errors/stackoverflow.ml index ad70d0cadb..241f6b7ab3 100644 --- a/testsuite/tests/runtime-errors/stackoverflow.ml +++ b/testsuite/tests/runtime-errors/stackoverflow.ml @@ -1,3 +1,28 @@ +(* TEST + +flags = "-w a" + +* setup-ocamlc.byte-build-env +** ocamlc.byte +*** run +**** check-program-output + +* libwin32unix +** setup-ocamlopt.byte-build-env +*** ocamlopt.byte +**** run +***** check-program-output + +* libunix +** script +script = "sh ${test_source_directory}/has-stackoverflow-detection" +*** setup-ocamlopt.byte-build-env +**** ocamlopt.byte +***** run +****** check-program-output + +*) + let rec f x = if not (x = 0 || x = 10000 || x = 20000) then 1 + f (x + 1) diff --git a/testsuite/tests/runtime-errors/stackoverflow.native.checker b/testsuite/tests/runtime-errors/stackoverflow.native.checker deleted file mode 100644 index f640718a69..0000000000 --- a/testsuite/tests/runtime-errors/stackoverflow.native.checker +++ /dev/null @@ -1,16 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Damien Doligez, projet Gallium, INRIA Rocquencourt * -#* * -#* Copyright 2013 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -$DIFF stackoverflow.native.reference stackoverflow.native.result diff --git a/testsuite/tests/runtime-errors/stackoverflow.bytecode.reference b/testsuite/tests/runtime-errors/stackoverflow.reference index a62a27b545..a62a27b545 100644 --- a/testsuite/tests/runtime-errors/stackoverflow.bytecode.reference +++ b/testsuite/tests/runtime-errors/stackoverflow.reference diff --git a/testsuite/tests/runtime-errors/stackoverflow.run b/testsuite/tests/runtime-errors/stackoverflow.run new file mode 100644 index 0000000000..acd7368b85 --- /dev/null +++ b/testsuite/tests/runtime-errors/stackoverflow.run @@ -0,0 +1,16 @@ +#!/bin/sh +ul=`ulimit -s` +if ( [ "$ul" = "unlimited" ] || [ $ul -gt 4096 ] ) ; then + ulimit -s 1024 && ul=true || ul=false ; +else + ul=true; +fi + +if $ul; then + ${program} > ${output} 2>&1; +else + # The test is not actually run + # We thus tell ocamltest the test output is equal to the reference file + # so that the comparison between reference and output will still succeed + echo output="${reference}" > ${ocamltest_response} +fi diff --git a/testsuite/tests/runtime-errors/syserror.bytecode.checker b/testsuite/tests/runtime-errors/syserror.bytecode.checker deleted file mode 100644 index 6433b1483c..0000000000 --- a/testsuite/tests/runtime-errors/syserror.bytecode.checker +++ /dev/null @@ -1,16 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Damien Doligez, projet Gallium, INRIA Rocquencourt * -#* * -#* Copyright 2013 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -grep 'Fatal error: exception Sys_error' syserror.bytecode.result >/dev/null diff --git a/testsuite/tests/runtime-errors/syserror.ml b/testsuite/tests/runtime-errors/syserror.ml index 46f62eadb0..39818a21f2 100644 --- a/testsuite/tests/runtime-errors/syserror.ml +++ b/testsuite/tests/runtime-errors/syserror.ml @@ -1 +1,31 @@ +(* TEST + +flags = "-w a" + +* setup-ocamlc.byte-build-env +** ocamlc.byte +*** run +exit_status = "2" +**** libunix +***** check-program-output +reference = "${test_source_directory}/syserror.unix.reference" +**** libwin32unix +***** check-program-output +reference = "${test_source_directory}/syserror.win32.reference" + +* setup-ocamlopt.byte-build-env +** ocamlopt.byte +*** run +exit_status = "2" +**** libunix +***** check-program-output +reference = "${test_source_directory}/syserror.unix.reference" +**** libwin32unix +***** check-program-output +reference = "${test_source_directory}/syserror.win32.reference" + +*) + +let _ = Printexc.record_backtrace false + let channel = open_out "titi:/toto" diff --git a/testsuite/tests/runtime-errors/syserror.native.checker b/testsuite/tests/runtime-errors/syserror.native.checker deleted file mode 100644 index 41448fffc4..0000000000 --- a/testsuite/tests/runtime-errors/syserror.native.checker +++ /dev/null @@ -1,16 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Damien Doligez, projet Gallium, INRIA Rocquencourt * -#* * -#* Copyright 2013 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -grep 'Fatal error: exception Sys_error' syserror.native.result >/dev/null diff --git a/testsuite/tests/runtime-errors/syserror.native.reference b/testsuite/tests/runtime-errors/syserror.native.reference deleted file mode 100644 index 3f6219a225..0000000000 --- a/testsuite/tests/runtime-errors/syserror.native.reference +++ /dev/null @@ -1 +0,0 @@ -Fatal error: exception Sys_error("titi:/toto: No such file or directory") diff --git a/testsuite/tests/runtime-errors/syserror.bytecode.reference b/testsuite/tests/runtime-errors/syserror.unix.reference index 3f6219a225..3f6219a225 100644 --- a/testsuite/tests/runtime-errors/syserror.bytecode.reference +++ b/testsuite/tests/runtime-errors/syserror.unix.reference diff --git a/testsuite/tests/runtime-errors/syserror.win32.reference b/testsuite/tests/runtime-errors/syserror.win32.reference new file mode 100644 index 0000000000..4030c3ad87 --- /dev/null +++ b/testsuite/tests/runtime-errors/syserror.win32.reference @@ -0,0 +1 @@ +Fatal error: exception Sys_error("titi:/toto: Invalid argument") diff --git a/testsuite/tests/tool-ocamldep-modalias/Makefile b/testsuite/tests/tool-ocamldep-modalias/Makefile deleted file mode 100644 index 476a8ace70..0000000000 --- a/testsuite/tests/tool-ocamldep-modalias/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -# Test for ocamldep and -no-alias-deps -# There are two versions: -# Makefile.build uses -no-alias-deps only for lib.ml/mli -# Makefile.build2 has no lib.ml, and uses -no-alias-deps for components too - -OCAMLDEP=$(OCAMLRUN) $(OTOPDIR)/tools/ocamldep -SOURCES = A.ml B.ml C.ml D.ml -LINKS = $(SOURCES:%=Lib%) -DEPENDS = depend.mk depend.mk2 depend.mod depend.mod2 depend.mod3 - -all: clean - @$(MAKE) build > /dev/null - @$(MAKE) $(DEPENDS) > /dev/null - @$(MAKE) compare - -build: depend.mk depend.mk2 - rm -f $(LINKS) - if $(NATIVECODE_ONLY); then : ; else \ - $(MAKE) -f Makefile.build byte; \ - rm -f *.cm* lib.ml; \ - $(MAKE) -f Makefile.build2 byte; fi - if $(BYTECODE_ONLY); then :; else \ - $(MAKE) -f Makefile.build opt; \ - rm -f *.cm* lib.ml; \ - $(MAKE) -f Makefile.build2 opt; fi - -# Create links for prefixed versions of the components -Lib%.ml: %.ml - cp $< $@ - -# Dependencies for Makefile.build, compiling and linking lib.cmo -depend.mk: $(LINKS) - cp lib_impl.ml lib.ml - $(OCAMLDEP) -as-map lib.ml lib.mli > $@ - $(OCAMLDEP) -map lib.ml -open Lib $(LINKS) >> $@ - -# Dependencies for Makefile.build2, not compiling lib.cmo -depend.mk2: $(LINKS) - rm -f lib.ml - $(OCAMLDEP) -map lib.mli -open Lib \ - $(LINKS) > $@ - -# Others tests for ocamldep -depend.mod: $(LINKS) - cp lib_impl.ml lib.ml - $(OCAMLDEP) -as-map -modules lib.ml lib.mli > $@ - $(OCAMLDEP) -modules -map lib.ml -open Lib $(LINKS) >> $@ - -depend.mod2: $(LINKS) - rm -f lib.ml - $(OCAMLDEP) -modules -map lib.mli $(LINKS) > $@ - -depend.mod3: $(LINKS) - rm -f lib.ml - $(OCAMLDEP) -modules -as-map -map lib.mli -open Lib \ - $(LINKS) > $@ - -promote: - for i in $(DEPENDS); do cp $$i $$i.reference; done - -compare: $(DEPENDS) - @rm -f $(LINKS) lib.ml - @for i in $(DEPENDS); do \ - printf " ... testing '$$i':"; \ - $(DIFF) $$i.reference $$i > /dev/null \ - && echo " => passed" || echo " => failed"; \ - done - -clean: - @rm -f *.cm* *.$(O) *.$(A) $(DEPENDS) $(LINKS) lib.ml *~ *.byt* *.opt* - -BASEDIR=../.. -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/tool-ocamldep-modalias/Makefile.build b/testsuite/tests/tool-ocamldep-modalias/Makefile.build index 17c61dfbef..a28f99d4ac 100644 --- a/testsuite/tests/tool-ocamldep-modalias/Makefile.build +++ b/testsuite/tests/tool-ocamldep-modalias/Makefile.build @@ -1,29 +1,43 @@ # Makefile using -no-alias-deps only for lib.ml/mli +# Note: not using pattern rules here is intended. +# This is to be as portable as possible since this Makefile +# will not necessarily be ran by GNU make +# The same holds for $< and $@ + SOURCES = A.ml B.ml C.ml D.ml OBJECTS = lib.cmo $(SOURCES:%.ml=Lib%.cmo) NOBJECTS = $(OBJECTS:%.cmo=%.cmx) byte: main.byt -opt: main.opt +opt: clean main.opt main.byt: lib.cma main.cmo $(OCAMLC) lib.cma main.cmo -o $@ lib.ml: lib_impl.ml - cp $< $@ + cp lib_impl.ml lib.ml lib.cma: $(OBJECTS) $(OCAMLC) -a -o $@ $(OBJECTS) lib.cmi: lib.mli - $(OCAMLC) -c -no-alias-deps -w -49 $< + $(OCAMLC) -c -no-alias-deps -w -49 lib.mli lib.cmo: lib.ml - $(OCAMLC) -c -no-alias-deps -w -49 $< + $(OCAMLC) -c -no-alias-deps -w -49 lib.ml + +LibA.cmo: A.ml + $(OCAMLC) -c -open Lib -o LibA.cmo A.ml + +LibB.cmo: B.ml + $(OCAMLC) -c -open Lib -o LibB.cmo B.ml -Lib%.cmo: %.ml - $(OCAMLC) -c -open Lib -o $@ $< +LibC.cmo: C.ml + $(OCAMLC) -c -open Lib -o LibC.cmo C.ml + +LibD.cmo: D.ml + $(OCAMLC) -c -open Lib -o LibD.cmo D.ml main.opt: lib.cmxa main.cmx $(OCAMLOPT) lib.cmxa main.cmx -o $@ @@ -34,10 +48,28 @@ lib.cmxa: $(NOBJECTS) lib.cmx: lib.ml $(OCAMLOPT) -c -no-alias-deps -w -49 $< -Lib%.cmx: %.ml - $(OCAMLOPT) -c -open Lib -o $@ $< +LibA.cmx: A.ml + $(OCAMLOPT) -c -open Lib -o LibA.cmx A.ml + +LibB.cmx: B.ml + $(OCAMLOPT) -c -open Lib -o LibB.cmx B.ml + +LibC.cmx: C.ml + $(OCAMLOPT) -c -open Lib -o LibC.cmx C.ml + +LibD.cmx: D.ml + $(OCAMLOPT) -c -open Lib -o LibD.cmx D.ml include depend.mk -BASEDIR=../.. -include $(BASEDIR)/makefiles/Makefile.common +.PHONY: clean +clean: + rm -f *.cm* lib.ml + +.SUFFIXES: .ml .cmo .cmx + +.ml.cmo: + $(OCAMLC) -c $< + +.ml.cmx: + $(OCAMLOPT) -c $< diff --git a/testsuite/tests/tool-ocamldep-modalias/Makefile.build2 b/testsuite/tests/tool-ocamldep-modalias/Makefile.build2 index a75477b968..e9b1d690a5 100644 --- a/testsuite/tests/tool-ocamldep-modalias/Makefile.build2 +++ b/testsuite/tests/tool-ocamldep-modalias/Makefile.build2 @@ -1,38 +1,63 @@ # Makefile using -no-alias-deps for all files, no need to link lib.cmo +# Note: not using pattern rules here is intended. +# This is to be as portable as possible since this Makefile +# will not necessarily be ran by GNU make +# The same holds for $< and $@ + SOURCES = A.ml B.ml C.ml OBJECTS = $(SOURCES:%.ml=Lib%.cmo) NOBJECTS = $(OBJECTS:%.cmo=%.cmx) byte: main.byt2 -opt: main.opt2 +opt: clean main.opt2 main.byt2: lib2.cma main.cmo - $(OCAMLC) lib2.cma main.cmo -o $@ + $(OCAMLC) -no-alias-deps lib2.cma main.cmo -o main.byt2 lib2.cma: $(OBJECTS) - $(OCAMLC) -a -o $@ $(OBJECTS) + $(OCAMLC) -no-alias-deps -a -o lib2.cma $(OBJECTS) lib.cmi: lib.mli - $(OCAMLC) -c -w -49 $< + $(OCAMLC) -no-alias-deps -c -w -49 lib.mli + +LibA.cmo: A.ml + $(OCAMLC) -no-alias-deps -c -open Lib -o LibA.cmo A.ml -Lib%.cmo: %.ml - $(OCAMLC) -c -open Lib -o $@ $< +LibB.cmo: B.ml + $(OCAMLC) -no-alias-deps -c -open Lib -o LibB.cmo B.ml + +LibC.cmo: C.ml + $(OCAMLC) -no-alias-deps -c -open Lib -o LibC.cmo C.ml main.opt2: lib.cmxa main.cmx - $(OCAMLOPT) lib.cmxa main.cmx -o $@ + $(OCAMLOPT) -no-alias-deps lib.cmxa main.cmx -o main.opt2 lib.cmxa: $(NOBJECTS) - $(OCAMLOPT) -a -o $@ $(NOBJECTS) + $(OCAMLOPT) -no-alias-deps -a -o lib.cmxa $(NOBJECTS) lib.cmx: lib.ml - $(OCAMLOPT) -c -no-alias-deps -w -49 $< + $(OCAMLOPT) -no-alias-deps -c -w -49 lib.ml + +LibA.cmx: A.ml + $(OCAMLOPT) -no-alias-deps -c -open Lib -o LibA.cmx A.ml -Lib%.cmx: %.ml - $(OCAMLOPT) -c -open Lib -o $@ $< +LibB.cmx: B.ml + $(OCAMLOPT) -no-alias-deps -c -open Lib -o LibB.cmx B.ml + +LibC.cmx: C.ml + $(OCAMLOPT) -no-alias-deps -c -open Lib -o LibC.cmx C.ml include depend.mk2 -BASEDIR=../.. -include $(BASEDIR)/makefiles/Makefile.common -COMPFLAGS = -no-alias-deps # Used by $(OCAMLC) +.PHONY: clean +clean: + rm -f *.cm* lib.ml + +.SUFFIXES: .ml .cmo .cmx + +.ml.cmo: + $(OCAMLC) -no-alias-deps -c $< + +.ml.cmx: + $(OCAMLOPT) -no-alias-deps -c $< diff --git a/testsuite/tests/tool-ocamldep-modalias/main.ml b/testsuite/tests/tool-ocamldep-modalias/main.ml index 946689127b..6ee66fd145 100644 --- a/testsuite/tests/tool-ocamldep-modalias/main.ml +++ b/testsuite/tests/tool-ocamldep-modalias/main.ml @@ -1,3 +1,86 @@ +(* TEST + +files = "A.ml B.ml C.ml D.ml lib_impl.ml lib.mli" + +script = "sh ${test_source_directory}/setup-links" +set sources = "A.ml B.ml C.ml D.ml" +set links = "LibA.ml LibB.ml LibC.ml LibD.ml" +set stdlib = "-nostdlib -I ${ocamlsrcdir}/stdlib" +set OCAMLC = "${ocamlrun} ${ocamlc_byte} ${stdlib}" +set OCAMLOPT = "${ocamlrun} ${ocamlopt_byte} ${stdlib}" + +* setup-ocamlc.byte-build-env +compiler_directory_suffix = ".depend.mk" +compiler_output = "${test_build_directory}/depend.mk" +** script +*** script +script = "cp lib_impl.ml lib.ml" +**** ocamlc.byte +commandline = "-depend -as-map lib.ml lib.mli" +***** ocamlc.byte +commandline = "-depend -map lib.ml -open Lib ${links}" +****** check-ocamlc.byte-output +compiler_reference = "${test_source_directory}/depend.mk.reference" +******* libunix +******** script +script = "cp ${test_source_directory}/Makefile.build Makefile" +********* script +script = "rm -f ${links}" +********** script +script = "${MAKE} byte" +*********** native-compiler +************ script +script = "${MAKE} opt" + +* setup-ocamlc.byte-build-env +compiler_directory_suffix = ".depend.mk2" +compiler_output = "${test_build_directory}/depend.mk2" +** script +*** ocamlc.byte +commandline = "-depend -map lib.mli -open Lib ${links}" +**** check-ocamlc.byte-output +compiler_reference = "${test_source_directory}/depend.mk2.reference" +***** libunix +****** script +script = "rm -f ${links}" +******* script +script = "cp ${test_source_directory}/Makefile.build2 Makefile" +******** script +script = "${MAKE} byte" +********* native-compiler +********** script +script = "${MAKE} opt" + +* setup-ocamlc.byte-build-env +compiler_directory_suffix = ".depend.mod" +** script +*** script +script = "cp lib_impl.ml lib.ml" +**** ocamlc.byte +commandline = "-depend -as-map -modules lib.ml lib.mli" +***** ocamlc.byte +commandline = "-depend -modules -map lib.ml -open Lib ${links}" +****** check-ocamlc.byte-output +compiler_reference = "${test_source_directory}/depend.mod.reference" + +* setup-ocamlc.byte-build-env +compiler_directory_suffix = ".depend.mod2" +** script +*** ocamlc.byte +commandline = "-depend -modules -map lib.mli ${links}" +**** check-ocamlc.byte-output +compiler_reference = "${test_source_directory}/depend.mod2.reference" + +* setup-ocamlc.byte-build-env +compiler_directory_suffix = ".depend.mod3" +** script +*** ocamlc.byte +commandline = "-depend -modules -as-map -map lib.mli -open Lib ${links}" +**** check-ocamlc.byte-output +compiler_reference = "${test_source_directory}/depend.mod3.reference" + +*) + open Lib let () = Printf.printf "B.g 3 = %d\n%!" (B.g 3) diff --git a/testsuite/tests/tool-ocamldep-modalias/ocamltests b/testsuite/tests/tool-ocamldep-modalias/ocamltests new file mode 100644 index 0000000000..d389d15661 --- /dev/null +++ b/testsuite/tests/tool-ocamldep-modalias/ocamltests @@ -0,0 +1 @@ +main.ml diff --git a/testsuite/tests/tool-ocamldep-modalias/setup-links b/testsuite/tests/tool-ocamldep-modalias/setup-links new file mode 100644 index 0000000000..1197fff1e0 --- /dev/null +++ b/testsuite/tests/tool-ocamldep-modalias/setup-links @@ -0,0 +1,2 @@ +#!/bin/sh +for i in A B C D; do cp $i.ml Lib$i.ml; done diff --git a/testsuite/tests/typing-gadts/ocamltests b/testsuite/tests/typing-gadts/ocamltests index ace6ac47cb..e7ca023188 100644 --- a/testsuite/tests/typing-gadts/ocamltests +++ b/testsuite/tests/typing-gadts/ocamltests @@ -43,6 +43,7 @@ pr7618.ml pr7747.ml term-conv.ml test.ml +unexpected_existentials.ml unify_mb.ml variables_in_mcomp.ml yallop_bugs.ml diff --git a/testsuite/tests/typing-gadts/unexpected_existentials.ml b/testsuite/tests/typing-gadts/unexpected_existentials.ml new file mode 100644 index 0000000000..c1585ad850 --- /dev/null +++ b/testsuite/tests/typing-gadts/unexpected_existentials.ml @@ -0,0 +1,158 @@ +(* TEST + * expect +*) +(** Test the error message for existential types apparearing + in unexpected position *) +type any = Any: 'a -> any +[%%expect {| +type any = Any : 'a -> any +|}] + +let Any x = Any () +[%%expect {| +Line _, characters 4-9: + let Any x = Any () + ^^^^^ +Error: Existential types are not allowed in toplevel bindings, +but this pattern introduces the existential type $Any_'a. +|}] + +let () = + let Any x = Any () and () = () in + () +[%%expect {| +Line _, characters 6-11: + let Any x = Any () and () = () in + ^^^^^ +Error: Existential types are not allowed in "let ... and ..." bindings, +but this pattern introduces the existential type $Any_'a. +|}] + + +let () = + let rec Any x = Any () in + () +[%%expect {| +Line _, characters 10-15: + let rec Any x = Any () in + ^^^^^ +Error: Existential types are not allowed in recursive bindings, +but this pattern introduces the existential type $Any_'a. +|}] + + +let () = + let[@attribute] Any x = Any () in + () +[%%expect {| +Line _, characters 18-23: + let[@attribute] Any x = Any () in + ^^^^^ +Error: Existential types are not allowed in presence of attributes, +but this pattern introduces the existential type $Any_'a. +|}] + + +class c (Any x) = object end +[%%expect {| +Line _, characters 8-15: + class c (Any x) = object end + ^^^^^^^ +Error: Existential types are not allowed in class arguments, +but this pattern introduces the existential type $Any_'a. +|}] + +class c = object(Any x)end +[%%expect {| +Line _, characters 16-23: + class c = object(Any x)end + ^^^^^^^ +Error: Existential types are not allowed in self patterns, +but this pattern introduces the existential type $Any_'a. +|}] + +type other = Any: _ -> other +[%%expect {| +type other = Any : 'a -> other +|}] + +let Any x = Any () +[%%expect {| +Line _, characters 4-9: + let Any x = Any () + ^^^^^ +Error: Existential types are not allowed in toplevel bindings, +but the constructor Any introduces existential types. +|}] + + +class c = let Any _x = () in object end +[%%expect {| +Line _, characters 14-20: + class c = let Any _x = () in object end + ^^^^^^ +Error: Existential types are not allowed in bindings inside class definition, +but the constructor Any introduces existential types. +|}] + +let () = + let Any x = Any () and () = () in + () +[%%expect {| +Line _, characters 6-11: + let Any x = Any () and () = () in + ^^^^^ +Error: Existential types are not allowed in "let ... and ..." bindings, +but the constructor Any introduces existential types. +|}] + + +let () = + let rec Any x = Any () in + () +[%%expect {| +Line _, characters 10-15: + let rec Any x = Any () in + ^^^^^ +Error: Existential types are not allowed in recursive bindings, +but the constructor Any introduces existential types. +|}] + + +let () = + let[@attribute] Any x = Any () in + () +[%%expect {| +Line _, characters 18-23: + let[@attribute] Any x = Any () in + ^^^^^ +Error: Existential types are not allowed in presence of attributes, +but the constructor Any introduces existential types. +|}] + +class c (Any x) = object end +[%%expect {| +Line _, characters 8-15: + class c (Any x) = object end + ^^^^^^^ +Error: Existential types are not allowed in class arguments, +but the constructor Any introduces existential types. +|}] + +class c = object(Any x) end +[%%expect {| +Line _, characters 16-23: + class c = object(Any x) end + ^^^^^^^ +Error: Existential types are not allowed in self patterns, +but the constructor Any introduces existential types. +|}] + +class c = let Any _x = () in object end +[%%expect {| +Line _, characters 14-20: + class c = let Any _x = () in object end + ^^^^^^ +Error: Existential types are not allowed in bindings inside class definition, +but the constructor Any introduces existential types. +|}] diff --git a/testsuite/tests/typing-poly/poly.ml b/testsuite/tests/typing-poly/poly.ml index 5f727c4e5a..70d6810b41 100644 --- a/testsuite/tests/typing-poly/poly.ml +++ b/testsuite/tests/typing-poly/poly.ml @@ -21,6 +21,34 @@ val f : 'a list -> 'a fold = <fun> - : int = 6 |}];; +type pty = {pv : 'a. 'a list};; +[%%expect {| +type pty = { pv : 'a. 'a list; } +|}];; + + +let px = {pv = []};; +[%%expect {| +val px : pty = {pv = []} +|}];; + +match px with +| {pv=[]} -> "OK" +| {pv=5::_} -> "int" +| {pv=true::_} -> "bool";; +[%%expect {| +Line _, characters 3-5: + | {pv=5::_} -> "int" + ^^ +Error: The record field pv is polymorphic. + You cannot instantiate it in a pattern. +|}];; + +fun {pv=v} -> true::v, 1::v;; +[%%expect {| +- : pty -> bool list * int list = <fun> +|}];; + class ['b] ilist l = object val l = l method add x = {< l = x :: l >} diff --git a/testsuite/tests/unboxed-primitive-args/Makefile b/testsuite/tests/unboxed-primitive-args/Makefile deleted file mode 100644 index 7a5c5ef10c..0000000000 --- a/testsuite/tests/unboxed-primitive-args/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -#************************************************************************** -#* * -#* OCaml * -#* * -#* Jeremie Dimino, Jane Street Europe * -#* * -#* Copyright 2015 Institut National de Recherche en Informatique et * -#* en Automatique. * -#* * -#* All rights reserved. This file is distributed under the terms of * -#* the GNU Lesser General Public License version 2.1, with the * -#* special exception on linking described in the file LICENSE. * -#* * -#************************************************************************** - -BASEDIR=../.. -LIBRARIES=unix bigarray -MODULES=common -MAIN_MODULE=main -C_FILES=test_common stubs -C_INCLUDES=-I $(OTOPDIR)/otherlibs/bigarray -ADD_COMPFLAGS=-I $(OTOPDIR)/otherlibs/bigarray \ - -I $(OTOPDIR)/otherlibs/$(UNIXLIB) - -include $(BASEDIR)/makefiles/Makefile.one -include $(BASEDIR)/makefiles/Makefile.common - -NATIVECODE_ONLY=true -NATIVECCCOMPOPTS+=-I $(OTOPDIR)/otherlibs/bigarray -GENERATED_SOURCES+=main.ml stubs.c - -main.ml: gen_test.ml - @$(OCAML) gen_test.ml ml > $@ - -stubs.c: gen_test.ml - @$(OCAML) gen_test.ml c > $@ - -common.cmx: common.cmi - -compile: stubs.c diff --git a/testsuite/tests/unboxed-primitive-args/ocamltests b/testsuite/tests/unboxed-primitive-args/ocamltests new file mode 100644 index 0000000000..31c13b4431 --- /dev/null +++ b/testsuite/tests/unboxed-primitive-args/ocamltests @@ -0,0 +1 @@ +test.ml diff --git a/testsuite/tests/unboxed-primitive-args/test.ml b/testsuite/tests/unboxed-primitive-args/test.ml new file mode 100644 index 0000000000..d94535a662 --- /dev/null +++ b/testsuite/tests/unboxed-primitive-args/test.ml @@ -0,0 +1,21 @@ +(* TEST + +include unix + +files = "common.mli common.ml test_common.c test_common.h" + +* setup-ocamlopt.byte-build-env +** ocaml +test_file = "${test_source_directory}/gen_test.ml" +ocaml_script_as_argument = "true" +arguments = "c" +compiler_output = "stubs.c" +*** ocaml +arguments = "ml" +compiler_output = "main.ml" +**** ocamlopt.byte +all_modules = "test_common.c stubs.c common.mli common.ml main.ml" +***** run +****** check-program-output + +*) diff --git a/testsuite/tests/unboxed-primitive-args/main.reference b/testsuite/tests/unboxed-primitive-args/test.reference index e69de29bb2..e69de29bb2 100644 --- a/testsuite/tests/unboxed-primitive-args/main.reference +++ b/testsuite/tests/unboxed-primitive-args/test.reference diff --git a/testsuite/tests/unwind/Makefile b/testsuite/tests/unwind/Makefile deleted file mode 100644 index ad88faf936..0000000000 --- a/testsuite/tests/unwind/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -BASEDIR=../.. - -# The -keep_dwarf_unwind option of ld was introduced in ld version 224.1. -# (The last released version where it is not supported is version 136.) -default: - @printf " ... testing 'unwind_test':" - @if [ ! $(SYSTEM) = macosx ]; then \ - echo " => skipped (not on Mac OSX)"; \ - elif $(BYTECODE_ONLY); then \ - echo " => skipped (bytecode only)"; \ - else \ - LDFULL="`ld -v 2>&1`"; \ - LD="`echo $$LDFULL | grep -o \"ld64-[0-9]*\"`"; \ - LDVER="`echo $$LD | sed \"s/ld64-//\"`"; \ - if [[ -z "$$LD" ]]; then \ - echo " => skipped (unknown linker: pattern ld64-[0-9]* not found" \ - echo " in 'ld -v' output)"; \ - elif [[ $$LDVER -lt 224 ]]; then \ - echo " => skipped (ld version is $$LDVER, only 224 or above " \ - echo " are supported)"; \ - else \ - $(MAKE) native_macosx_tests; \ - fi; \ - fi - -native_macosx_tests: - @$(MAKE) clean ; $(MAKE) unwind_test && \ - ./unwind_test >/dev/null 2>&1 && echo " => passed" || echo " => failed" - -unwind_test: - @$(OCAMLOPT) -c -opaque mylib.mli - @$(OCAMLOPT) -c driver.ml - @$(OCAMLOPT) -c mylib.ml - @$(OCAMLOPT) -ccopt -I -ccopt $(CTOPDIR)/byterun -c stack_walker.c - @$(OCAMLOPT) -cclib -Wl,-keep_dwarf_unwind -o unwind_test mylib.cmx \ - driver.cmx stack_walker.o - -clean: - @rm -f *.cm* *.o unwind_test - -include $(BASEDIR)/makefiles/Makefile.common diff --git a/testsuite/tests/unwind/check-linker-version b/testsuite/tests/unwind/check-linker-version new file mode 100644 index 0000000000..0b15681e5d --- /dev/null +++ b/testsuite/tests/unwind/check-linker-version @@ -0,0 +1,16 @@ +#!/bin/sh +exec > ${ocamltest_response} 2>&1 +LDFULL="`ld -v 2>&1`" +LD="`echo $LDFULL | grep -o \"ld64-[0-9]*\"`" +LDVER="`echo $LD | sed \"s/ld64-//\"`" +if [[ -z "$LD" ]]; then + echo "unknown linker: pattern ld64-[0-9]* not found in 'ld -v' output"; + test_result=${TEST_SKIP}; +elif [[ $LDVER -lt 224 ]]; then + echo "ld version is $LDVER, only 224 or above are supported"; + test_result=${TEST_SKIP}; +else + test_reslut=${TEST_PASS}; +fi + +exit ${TEST_RESULT} diff --git a/testsuite/tests/unwind/driver.ml b/testsuite/tests/unwind/driver.ml index cd289b6b35..e756ef5075 100644 --- a/testsuite/tests/unwind/driver.ml +++ b/testsuite/tests/unwind/driver.ml @@ -1,3 +1,23 @@ +(* TEST + +script = "sh ${test_source_directory}/check-linker-version" +files = "mylib.mli mylib.ml stack_walker.c" + +* macos +** script +*** setup-ocamlopt.byte-build-env +**** ocamlopt.byte +flags = "-opaque" +module = "mylib.mli" +***** ocamlopt.byte +module = "" +flags = "-cclib -Wl,-keep_dwarf_unwind" +all_modules = "mylib.ml driver.ml stack_walker.c" +program = "${test_build_directory}/unwind_test" +****** run + +*) + let () = Mylib.foo1 Mylib.bar 1 2 3 4 5 6 7 8 9 10; Mylib.foo2 Mylib.baz 1 2 3 4 5 6 7 8 9 10 diff --git a/testsuite/tests/unwind/ocamltests b/testsuite/tests/unwind/ocamltests new file mode 100644 index 0000000000..6550b8e3dc --- /dev/null +++ b/testsuite/tests/unwind/ocamltests @@ -0,0 +1 @@ +driver.ml diff --git a/testsuite/tests/warnings/ocamltests b/testsuite/tests/warnings/ocamltests index 2f143cf83a..fa3318d206 100644 --- a/testsuite/tests/warnings/ocamltests +++ b/testsuite/tests/warnings/ocamltests @@ -2,6 +2,7 @@ deprecated_module_assigment.ml deprecated_module.ml deprecated_module_use.ml w01.ml +w03.ml w04_failure.ml w04.ml w06.ml diff --git a/testsuite/tests/warnings/w03.compilers.reference b/testsuite/tests/warnings/w03.compilers.reference new file mode 100644 index 0000000000..7074abd227 --- /dev/null +++ b/testsuite/tests/warnings/w03.compilers.reference @@ -0,0 +1,4 @@ +File "w03.ml", line 14, characters 8-9: +Warning 3: deprecated: A +File "w03.ml", line 17, characters 15-25: +Warning 53: the "deprecated" attribute cannot appear in this context diff --git a/testsuite/tests/warnings/w03.ml b/testsuite/tests/warnings/w03.ml new file mode 100644 index 0000000000..b9f70b1df5 --- /dev/null +++ b/testsuite/tests/warnings/w03.ml @@ -0,0 +1,24 @@ +(* TEST + +flags = "-w A" + +* setup-ocamlc.byte-build-env +** ocamlc.byte +compile_only = "true" +*** check-ocamlc.byte-output + +*) + +exception A [@deprecated] + +let _ = A + + +exception B [@@deprecated] + +let _ = B + + +exception C [@deprecated] + +let _ = B [@warning "-53"] diff --git a/testsuite/tools/Makefile b/testsuite/tools/Makefile index 2abced57b8..219281844f 100644 --- a/testsuite/tools/Makefile +++ b/testsuite/tools/Makefile @@ -13,19 +13,70 @@ #************************************************************************** BASEDIR=.. -MAIN=expect_test -PROG=$(MAIN)$(EXE) -COMPFLAGS=-I $(OTOPDIR)/parsing -I $(OTOPDIR)/utils \ +include $(BASEDIR)/../config/Makefile +expect_MAIN=expect_test +expect_PROG=$(expect_MAIN)$(EXE) +expect_COMPFLAGS=-I $(OTOPDIR)/parsing -I $(OTOPDIR)/utils \ -I $(OTOPDIR)/driver -I $(OTOPDIR)/toplevel -LIBRARIES=../../compilerlibs/ocamlcommon \ +expect_LIBRARIES=../../compilerlibs/ocamlcommon \ ../../compilerlibs/ocamlbytecomp \ ../../compilerlibs/ocamltoplevel -$(PROG): $(MAIN).cmo $(LIBRARIES:=.cma) - $(OCAMLC) -linkall -o $(PROG) $(LIBRARIES:=.cma) $(MAIN).cmo +codegen_INCLUDES=\ + -I $(OTOPDIR)/parsing \ + -I $(OTOPDIR)/utils \ + -I $(OTOPDIR)/typing \ + -I $(OTOPDIR)/middle_end \ + -I $(OTOPDIR)/bytecomp \ + -I $(OTOPDIR)/asmcomp + +codegen_OTHEROBJECTS=\ + $(OTOPDIR)/compilerlibs/ocamlcommon.cma \ + $(OTOPDIR)/compilerlibs/ocamloptcomp.cma + +codegen_OBJECTS=parsecmmaux.cmo parsecmm.cmo lexcmm.cmo codegen_main.cmo + +codegen_ADD_COMPFLAGS=$(codegen_INCLUDES) -w -40 -g + +targets := $(expect_PROG) + +ifneq "$(ARCH)" "none" +targets += codegen +ifneq "$(CCOMPTYPE)-$(ARCH)" "msvc-amd64" +# The asmgen tests are not ported to MSVC64 yet +# so do not compile any arch-specific module +targets += asmgen_$(ARCH).$(O) +endif +endif + +all: $(targets) + +$(expect_PROG): $(expect_LIBRARIES:=.cma) $(expect_MAIN).cmo + @$(OCAMLC) -linkall -o $@ $^ include $(BASEDIR)/makefiles/Makefile.common .PHONY: clean clean: defaultclean - rm -f $(PROG) + rm -f $(expect_PROG) + rm -f codegen parsecmm.ml parsecmm.mli lexcmm.ml + +expect_test.cmo: COMPFLAGS=$(expect_COMPFLAGS) + +$(codegen_OBJECTS): ADD_COMPFLAGS = $(codegen_ADD_COMPFLAGS) + +codegen_main.cmo: parsecmm.cmo + +codegen: $(codegen_OBJECTS) + @$(OCAMLC) $(LINKFLAGS) -o $@ $(codegen_OTHEROBJECTS) $^ + +parsecmm.mli parsecmm.ml: parsecmm.mly + @$(OCAMLYACC) -q parsecmm.mly + +lexcmm.ml: lexcmm.mll + @$(OCAMLLEX) -q lexcmm.mll + +asmgen_i386.obj: asmgen_i386nt.asm + @set -o pipefail ; \ + $(ASM) $@ $^ | tail -n +2 + diff --git a/testsuite/tests/asmgen/amd64.S b/testsuite/tools/asmgen_amd64.S index fb87307df0..fb87307df0 100644 --- a/testsuite/tests/asmgen/amd64.S +++ b/testsuite/tools/asmgen_amd64.S diff --git a/testsuite/tests/asmgen/arm.S b/testsuite/tools/asmgen_arm.S index da6d9ee74f..da6d9ee74f 100644 --- a/testsuite/tests/asmgen/arm.S +++ b/testsuite/tools/asmgen_arm.S diff --git a/testsuite/tests/asmgen/arm64.S b/testsuite/tools/asmgen_arm64.S index 4b803d20b1..4b803d20b1 100644 --- a/testsuite/tests/asmgen/arm64.S +++ b/testsuite/tools/asmgen_arm64.S diff --git a/testsuite/tests/asmgen/i386.S b/testsuite/tools/asmgen_i386.S index 26dc83fcac..26dc83fcac 100644 --- a/testsuite/tests/asmgen/i386.S +++ b/testsuite/tools/asmgen_i386.S diff --git a/testsuite/tests/asmgen/i386nt.asm b/testsuite/tools/asmgen_i386nt.asm index 618d41c949..281f34ec52 100644 --- a/testsuite/tests/asmgen/i386nt.asm +++ b/testsuite/tools/asmgen_i386nt.asm @@ -47,19 +47,25 @@ _caml_c_call: PUBLIC _caml_alloc1 PUBLIC _caml_alloc2 PUBLIC _caml_alloc3 + PUBLIC _caml_allocN + PUBLIC _caml_extra_params + PUBLIC _caml_raise_exn _caml_call_gc: _caml_alloc: _caml_alloc1: _caml_alloc2: _caml_alloc3: +_caml_allocN: +_caml_extra_params: +_caml_raise_exn: int 3 .DATA PUBLIC _caml_exception_pointer _caml_exception_pointer dword 0 - PUBLIC _young_ptr -_young_ptr dword 0 - PUBLIC _young_limit -_young_limit dword 0 + PUBLIC _caml_young_ptr +_caml_young_ptr dword 0 + PUBLIC _caml_young_limit +_caml_young_limit dword 0 END diff --git a/testsuite/tests/asmgen/power.S b/testsuite/tools/asmgen_power.S index 71c692f97b..71c692f97b 100644 --- a/testsuite/tests/asmgen/power.S +++ b/testsuite/tools/asmgen_power.S diff --git a/testsuite/tests/asmgen/s390x.S b/testsuite/tools/asmgen_s390x.S index 99eeca2704..99eeca2704 100644 --- a/testsuite/tests/asmgen/s390x.S +++ b/testsuite/tools/asmgen_s390x.S diff --git a/testsuite/tests/asmgen/main.ml b/testsuite/tools/codegen_main.ml index 6970f99a93..6970f99a93 100644 --- a/testsuite/tests/asmgen/main.ml +++ b/testsuite/tools/codegen_main.ml diff --git a/testsuite/tools/expect_test.ml b/testsuite/tools/expect_test.ml index 497328cf03..660712b918 100644 --- a/testsuite/tools/expect_test.ml +++ b/testsuite/tools/expect_test.ml @@ -329,8 +329,11 @@ let process_expect_file fname = write_corrected ~file:corrected_fname ~file_contents correction let repo_root = ref None +let keep_original_error_size = ref false let main fname = + if not !keep_original_error_size then + Clflags.error_size := 0; Toploop.override_sys_argv (Array.sub Sys.argv ~pos:!Arg.current ~len:(Array.length Sys.argv - !Arg.current)); @@ -419,6 +422,8 @@ let args = ( [ "-repo-root", Arg.String (fun s -> repo_root := Some s), "<dir> root of the OCaml repository. This causes the tool to use \ the stdlib from the current source tree rather than the installed one." + ; "-keep-original-error-size", Arg.Set keep_original_error_size, + " truncate long error messages as the compiler would" ] @ Options.list ) @@ -427,7 +432,6 @@ let usage = "Usage: expect_test <options> [script-file [arguments]]\n\ let () = Clflags.color := Some Misc.Color.Never; - Clflags.error_size := 0; try Arg.parse args main usage; Printf.eprintf "expect_test: no input file\n"; diff --git a/testsuite/tests/asmgen/lexcmm.mli b/testsuite/tools/lexcmm.mli index f9fe6afadf..f9fe6afadf 100644 --- a/testsuite/tests/asmgen/lexcmm.mli +++ b/testsuite/tools/lexcmm.mli diff --git a/testsuite/tests/asmgen/lexcmm.mll b/testsuite/tools/lexcmm.mll index 81eab9d0a3..81eab9d0a3 100644 --- a/testsuite/tests/asmgen/lexcmm.mll +++ b/testsuite/tools/lexcmm.mll diff --git a/testsuite/tests/asmgen/parsecmm.mly b/testsuite/tools/parsecmm.mly index b597a01597..b597a01597 100644 --- a/testsuite/tests/asmgen/parsecmm.mly +++ b/testsuite/tools/parsecmm.mly diff --git a/testsuite/tests/asmgen/parsecmmaux.ml b/testsuite/tools/parsecmmaux.ml index db55527354..db55527354 100644 --- a/testsuite/tests/asmgen/parsecmmaux.ml +++ b/testsuite/tools/parsecmmaux.ml diff --git a/testsuite/tests/asmgen/parsecmmaux.mli b/testsuite/tools/parsecmmaux.mli index f5478579ee..f5478579ee 100644 --- a/testsuite/tests/asmgen/parsecmmaux.mli +++ b/testsuite/tools/parsecmmaux.mli diff --git a/tools/make-version-header.sh b/tools/make-version-header.sh index ce3b70c67c..707d04fa2b 100755 --- a/tools/make-version-header.sh +++ b/tools/make-version-header.sh @@ -39,7 +39,7 @@ case $# in esac major="`echo "$version" | sed -n -e '1s/^\([0-9]*\)\..*/\1/p'`" -minor="`echo "$version" | sed -n -e '1s/^[0-9]*\.\([0-9]*\).*/\1/p'`" +minor="`echo "$version" | sed -n -e '1s/^[0-9]*\.0*\([0-9]*\).*/\1/p'`" patchlvl="`echo "$version" | sed -n -e '1s/^[0-9]*\.[0-9]*\.\([0-9]*\).*/\1/p'`" suffix="`echo "$version" | sed -n -e '1s/^[^+]*+\(.*\)/\1/p'`" diff --git a/typing/ctype.ml b/typing/ctype.ml index f24e46d15a..5d6370e553 100644 --- a/typing/ctype.ml +++ b/typing/ctype.ml @@ -1145,17 +1145,17 @@ let new_declaration expansion_scope manifest = type_unboxed = unboxed_false_default_false; } +let existential_name cstr ty = match repr ty with + | {desc = Tvar (Some name)} -> "$" ^ cstr.cstr_name ^ "_'" ^ name + | _ -> "$" ^ cstr.cstr_name + let instance_constructor ?in_pattern cstr = begin match in_pattern with | None -> () | Some (env, expansion_scope) -> let process existential = let decl = new_declaration (Some expansion_scope) None in - let name = - match repr existential with - {desc = Tvar (Some name)} -> "$" ^ cstr.cstr_name ^ "_'" ^ name - | _ -> "$" ^ cstr.cstr_name - in + let name = existential_name cstr existential in let path = Path.Pident (Ident.create (get_new_abstract_name name)) in let new_env = Env.add_local_type path decl !env in env := new_env; diff --git a/typing/ctype.mli b/typing/ctype.mli index e22d2694b7..abc462e114 100644 --- a/typing/ctype.mli +++ b/typing/ctype.mli @@ -125,6 +125,7 @@ val generic_instance: type_expr -> type_expr (* Same as instance, but new nodes at generic_level *) val instance_list: type_expr list -> type_expr list (* Take an instance of a list of type schemes *) +val existential_name: constructor_description -> type_expr -> string val instance_constructor: ?in_pattern:Env.t ref * int -> constructor_description -> type_expr list * type_expr diff --git a/typing/env.ml b/typing/env.ml index cf5207ee85..41d3fe8346 100644 --- a/typing/env.ml +++ b/typing/env.ml @@ -1274,9 +1274,19 @@ let lookup_class = let lookup_cltype = lookup (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) -let copy_types l env = - let f desc = {desc with val_type = Subst.type_expr Subst.identity desc.val_type} in +type copy_of_types = { + to_copy: string list; + initial_values: value_description IdTbl.t; + new_values: value_description IdTbl.t; +} + +let make_copy_of_types l env : copy_of_types = + let f desc = { desc with val_type = Subst.type_expr Subst.identity desc.val_type} in let values = List.fold_left (fun env s -> IdTbl.update s f env) env.values l in + {to_copy = l; initial_values = env.values; new_values = values} + +let do_copy_types { to_copy = l; initial_values; new_values = values } env = + if initial_values != env.values then fatal_error "Env.do_copy_types"; {env with values; summary = Env_copy_types (env.summary, l)} let mark_value_used name vd = diff --git a/typing/env.mli b/typing/env.mli index 0110504a41..a76f36952e 100644 --- a/typing/env.mli +++ b/typing/env.mli @@ -127,8 +127,11 @@ val lookup_cltype: ?loc:Location.t -> ?mark:bool -> Longident.t -> t -> Path.t * class_type_declaration -val copy_types: string list -> t -> t - (* Used only in Typecore.duplicate_ident_types. *) +type copy_of_types +val make_copy_of_types: string list -> t -> copy_of_types +val do_copy_types: copy_of_types -> t -> t +(** [do_copy_types copy env] will raise a fatal error if the values in + [env] are different from the env passed to [make_copy_of_types]. *) exception Recmodule (* Raise by lookup_module when the identifier refers diff --git a/typing/envaux.ml b/typing/envaux.ml index caa67f38d6..b8425d5c05 100644 --- a/typing/envaux.ml +++ b/typing/envaux.ml @@ -80,7 +80,8 @@ let rec env_from_summary sum subst = (Subst.type_declaration subst info)) map (env_from_summary s subst) | Env_copy_types (s, sl) -> - Env.copy_types sl (env_from_summary s subst) + let env = env_from_summary s subst in + Env.do_copy_types (Env.make_copy_of_types sl env) env in Hashtbl.add env_cache (sum, subst) env; env diff --git a/typing/printtyped.ml b/typing/printtyped.ml index 1d06ad9b92..7f7f74ccfa 100644 --- a/typing/printtyped.ml +++ b/typing/printtyped.ml @@ -459,6 +459,14 @@ and type_extension i ppf x = list (i+1) extension_constructor ppf x.tyext_constructors; line i ppf "ptyext_private = %a\n" fmt_private_flag x.tyext_private; +and type_exception i ppf x = + line i ppf "type_exception\n"; + attributes i ppf x.tyexn_attributes; + let i = i+1 in + line i ppf "ptyext_constructor =\n"; + let i = i+1 in + extension_constructor i ppf x.tyexn_constructor + and extension_constructor i ppf x = line i ppf "extension_constructor %a\n" fmt_location x.ext_loc; attributes i ppf x.ext_attributes; @@ -669,7 +677,7 @@ and signature_item i ppf x = type_extension i ppf e; | Tsig_exception ext -> line i ppf "Tsig_exception\n"; - extension_constructor i ppf ext + type_exception i ppf ext | Tsig_module md -> line i ppf "Tsig_module \"%a\"\n" fmt_ident md.md_id; attributes i ppf md.md_attributes; @@ -775,7 +783,7 @@ and structure_item i ppf x = type_extension i ppf te | Tstr_exception ext -> line i ppf "Tstr_exception\n"; - extension_constructor i ppf ext; + type_exception i ppf ext; | Tstr_module x -> line i ppf "Tstr_module\n"; module_binding i ppf x diff --git a/typing/tast_mapper.ml b/typing/tast_mapper.ml index 36e33e3f2f..a5167d4fe1 100644 --- a/typing/tast_mapper.ml +++ b/typing/tast_mapper.ml @@ -57,6 +57,7 @@ type mapper = type_declarations: mapper -> (rec_flag * type_declaration list) -> (rec_flag * type_declaration list); type_extension: mapper -> type_extension -> type_extension; + type_exception: mapper -> type_exception -> type_exception; type_kind: mapper -> type_kind -> type_kind; value_binding: mapper -> value_binding -> value_binding; value_bindings: mapper -> (rec_flag * value_binding list) -> @@ -112,7 +113,7 @@ let structure_item sub {str_desc; str_loc; str_env} = let (rec_flag, list) = sub.type_declarations sub (rec_flag, list) in Tstr_type (rec_flag, list) | Tstr_typext te -> Tstr_typext (sub.type_extension sub te) - | Tstr_exception ext -> Tstr_exception (sub.extension_constructor sub ext) + | Tstr_exception ext -> Tstr_exception (sub.type_exception sub ext) | Tstr_module mb -> Tstr_module (sub.module_binding sub mb) | Tstr_recmodule list -> Tstr_recmodule (List.map (sub.module_binding sub) list) @@ -174,6 +175,12 @@ let type_extension sub x = in {x with tyext_constructors; tyext_params} +let type_exception sub x = + let tyexn_constructor = + sub.extension_constructor sub x.tyexn_constructor + in + {x with tyexn_constructor} + let extension_constructor sub x = let ext_kind = match x.ext_kind with @@ -374,7 +381,7 @@ let signature_item sub x = | Tsig_typext te -> Tsig_typext (sub.type_extension sub te) | Tsig_exception ext -> - Tsig_exception (sub.extension_constructor sub ext) + Tsig_exception (sub.type_exception sub ext) | Tsig_module x -> Tsig_module (sub.module_declaration sub x) | Tsig_recmodule list -> @@ -692,6 +699,7 @@ let default = type_declaration; type_declarations; type_extension; + type_exception; type_kind; value_binding; value_bindings; diff --git a/typing/tast_mapper.mli b/typing/tast_mapper.mli index 2251fa5709..3531341b04 100644 --- a/typing/tast_mapper.mli +++ b/typing/tast_mapper.mli @@ -56,6 +56,7 @@ type mapper = type_declarations: mapper -> (rec_flag * type_declaration list) -> (rec_flag * type_declaration list); type_extension: mapper -> type_extension -> type_extension; + type_exception: mapper -> type_exception -> type_exception; type_kind: mapper -> type_kind -> type_kind; value_binding: mapper -> value_binding -> value_binding; value_bindings: mapper -> (rec_flag * value_binding list) -> diff --git a/typing/typeclass.ml b/typing/typeclass.ml index 53542c5c0a..de8a339fde 100644 --- a/typing/typeclass.ml +++ b/typing/typeclass.ml @@ -1158,7 +1158,7 @@ and class_expr_aux cl_num val_env met_env scl = | Pcl_let (rec_flag, sdefs, scl') -> let (defs, val_env) = try - Typecore.type_let val_env rec_flag sdefs None + Typecore.type_let In_class_def val_env rec_flag sdefs None with Ctype.Unify [(ty, _)] -> raise(Error(scl.pcl_loc, val_env, Make_nongen_seltype ty)) in diff --git a/typing/typecore.ml b/typing/typecore.ml index 5849ce7bcb..17dc7d06b5 100644 --- a/typing/typecore.ml +++ b/typing/typecore.ml @@ -39,6 +39,15 @@ type type_expected = { explanation: type_forcing_context option; } +type existential_restriction = + | At_toplevel (** no existential types at the toplevel *) + | In_group (** nor with let ... and ... *) + | In_rec (** or recursive definition *) + | With_attributes (** or let[@any_attribute] = ... *) + | In_class_args (** or in class arguments *) + | In_class_def (** or in [class c = let ... in ...] *) + | In_self_pattern (** or in self pattern *) + type error = Polymorphic_label of Longident.t | Constructor_arity_mismatch of Longident.t * int * int @@ -80,7 +89,7 @@ type error = | Cannot_infer_signature | Not_a_packed_module of type_expr | Recursive_local_constraint of (type_expr * type_expr) list - | Unexpected_existential + | Unexpected_existential of existential_restriction * string * string list | Invalid_interval | Invalid_for_loop_index | No_value_clauses @@ -262,22 +271,6 @@ let iter_expression f e = expr e -let all_idents_cases el = - let idents = Hashtbl.create 8 in - let f = function - | {pexp_desc=Pexp_ident { txt = Longident.Lident id; _ }; _} -> - Hashtbl.replace idents id () - | _ -> () - in - List.iter - (fun cp -> - may (iter_expression f) cp.pc_guard; - iter_expression f cp.pc_rhs - ) - el; - Hashtbl.fold (fun x () rest -> x :: rest) idents [] - - (* Typing of constants *) let type_constant = function @@ -454,12 +447,16 @@ let has_variants p = (* pattern environment *) -let pattern_variables = ref ([] : - (Ident.t * type_expr * string loc * Location.t * bool (* as-variable *)) list) +type pattern_variable = + Ident.t * type_expr * string loc * Location.t * bool (* as-variable *) +type module_variable = + string loc * Location.t + +let pattern_variables = ref ([] : pattern_variable list) let pattern_force = ref ([] : (unit -> unit) list) let pattern_scope = ref (None : Annot.ident option);; let allow_modules = ref false -let module_variables = ref ([] : (string loc * Location.t) list) +let module_variables = ref ([] : module_variable list) let reset_pattern scope allow = pattern_variables := []; pattern_force := []; @@ -986,6 +983,35 @@ type type_pat_mode = | Inside_or (* inside a non-split or-pattern *) | Split_or (* always split or-patterns *) +(* "half typed" cases are produced in [type_cases] when we've just typechecked + the pattern but haven't type-checked the body yet. + At this point we might have added some type equalities to the environment, + but haven't yet added identifiers bound by the pattern. *) +type half_typed_case = + { typed_pat: pattern; + pat_type_for_unif: type_expr; + untyped_case: Parsetree.case; + branch_env: Env.t; + pat_vars: pattern_variable list; + unpacks: module_variable list; + contains_gadt: bool; } + +let all_idents_cases half_typed_cases = + let idents = Hashtbl.create 8 in + let f = function + | {pexp_desc=Pexp_ident { txt = Longident.Lident id; _ }; _} -> + Hashtbl.replace idents id () + | _ -> () + in + List.iter + (fun { untyped_case = cp; _ } -> + may (iter_expression f) cp.pc_guard; + iter_expression f cp.pc_rhs + ) + half_typed_cases; + Hashtbl.fold (fun x () rest -> x :: rest) idents [] + + exception Need_backtrack (* type_pat propagates the expected type as well as maps for @@ -1154,8 +1180,13 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env Env.mark_constructor Env.Pattern !env (Longident.last lid.txt) constr; Builtin_attributes.check_deprecated loc constr.cstr_attributes constr.cstr_name; - if no_existentials && constr.cstr_existentials <> [] then - raise (Error (loc, !env, Unexpected_existential)); + begin match no_existentials, constr.cstr_existentials with + | None, _ | _, [] -> () + | Some r, (_ :: _ as exs) -> + let exs = List.map (Ctype.existential_name constr) exs in + let name = constr.cstr_name in + raise (Error (loc, !env, Unexpected_existential (r,name, exs))) + end; (* if constructor is gadt, we must verify that the expected type has the correct head *) if constr.cstr_generalized then @@ -1189,7 +1220,8 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env constr in (* PR#7214: do not use gadt unification for toplevel lets *) - if not constr.cstr_generalized || mode = Inside_or || no_existentials + if not constr.cstr_generalized || mode = Inside_or + || no_existentials <> None then unify_pat_types loc !env ty_res expected_ty else unify_pat_types_gadt loc env ty_res expected_ty; @@ -1407,13 +1439,13 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env | Ppat_extension ext -> raise (Error_forward (Builtin_attributes.error_of_extension ext)) -let type_pat ?(allow_existentials=false) ?constrs ?labels ?(mode=Normal) +let type_pat ?no_existentials ?constrs ?labels ?(mode=Normal) ?(explode=0) ?(lev=get_current_level()) env sp expected_ty = gadt_equations_level := Some lev; try let r = - type_pat ~no_existentials:(not allow_existentials) ~constrs ~labels - ~mode ~explode ~env sp expected_ty (fun x -> x) in + type_pat ~no_existentials ~constrs ~labels ~mode ~explode ~env sp + expected_ty (fun x -> x) in iter_pattern (fun p -> p.pat_env <- !env) r; gadt_equations_level := None; r @@ -1431,8 +1463,7 @@ let partial_pred ~lev ?mode ?explode env expected_ty constrs labels p = reset_pattern None true; let typed_p = Ctype.with_passive_variants - (type_pat ~allow_existentials:true ~lev - ~constrs ~labels ?mode ?explode env p) + (type_pat ~lev ~constrs ~labels ?mode ?explode env p) expected_ty in set_state state env; @@ -1459,46 +1490,44 @@ let check_unused ?(lev=get_current_level ()) env expected_ty cases = | r -> r) cases -let add_pattern_variables ?check ?check_as env = - let pv = get_ref pattern_variables in - (List.fold_right - (fun (id, ty, _name, loc, as_var) env -> +let add_pattern_variables ?check ?check_as env pv = + List.fold_right + (fun (id, ty, _name, loc, as_var) env -> let check = if as_var then check_as else check in Env.add_value ?check id {val_type = ty; val_kind = Val_reg; Types.val_loc = loc; val_attributes = []; } env - ) - pv env, - get_ref module_variables) + ) + pv env let type_pattern ~lev env spat scope expected_ty = reset_pattern scope true; let new_env = ref env in - let pat = type_pat ~allow_existentials:true ~lev new_env spat expected_ty in - let new_env, unpacks = - add_pattern_variables !new_env - ~check:(fun s -> Warnings.Unused_var_strict s) - ~check_as:(fun s -> Warnings.Unused_var s) in - (pat, new_env, get_ref pattern_force, unpacks) - -let type_pattern_list env spatl scope expected_tys allow = + let pat = type_pat ~lev new_env spat expected_ty in + let pvs = get_ref pattern_variables in + let unpacks = get_ref module_variables in + (pat, !new_env, get_ref pattern_force, pvs, unpacks) + +let type_pattern_list no_existentials env spatl scope expected_tys allow = reset_pattern scope allow; let new_env = ref env in let type_pat (attrs, pat) ty = Builtin_attributes.warning_scope ~ppwarning:false attrs (fun () -> - type_pat new_env pat ty + type_pat ~no_existentials new_env pat ty ) in let patl = List.map2 type_pat spatl expected_tys in - let new_env, unpacks = add_pattern_variables !new_env in + let pvs = get_ref pattern_variables in + let unpacks = get_ref module_variables in + let new_env = add_pattern_variables !new_env pvs in (patl, new_env, get_ref pattern_force, unpacks) let type_class_arg_pattern cl_num val_env met_env l spat = reset_pattern None false; let nv = newvar () in - let pat = type_pat (ref val_env) spat nv in + let pat = type_pat ~no_existentials:In_class_args (ref val_env) spat nv in if has_variants pat then begin Parmatch.pressure_variants val_env [pat]; iter_pattern finalize_variant pat @@ -1521,7 +1550,7 @@ let type_class_arg_pattern cl_num val_env met_env l spat = env)) !pattern_variables ([], met_env) in - let val_env, _ = add_pattern_variables val_env in + let val_env = add_pattern_variables val_env (get_ref pattern_variables) in (pat, pv, val_env, met_env) let type_self_pattern cl_num privty val_env met_env par_env spat = @@ -1532,7 +1561,7 @@ let type_self_pattern cl_num privty val_env met_env par_env spat = in reset_pattern None false; let nv = newvar() in - let pat = type_pat (ref val_env) spat nv in + let pat = type_pat ~no_existentials:In_self_pattern (ref val_env) spat nv in List.iter (fun f -> f()) (get_ref pattern_force); let meths = ref Meths.empty in let vars = ref Vars.empty in @@ -1681,9 +1710,9 @@ and is_nonexpansive_mod mexp = | Tstr_recmodule id_mod_list -> List.for_all (fun {mb_expr=m;_} -> is_nonexpansive_mod m) id_mod_list - | Tstr_exception {ext_kind = Text_decl _} -> + | Tstr_exception {tyexn_constructor = {ext_kind = Text_decl _}} -> false (* true would be unsound *) - | Tstr_exception {ext_kind = Text_rebind _} -> true + | Tstr_exception {tyexn_constructor = {ext_kind = Text_rebind _}} -> true | Tstr_typext te -> List.for_all (function {ext_kind = Text_decl _} -> false @@ -2674,10 +2703,13 @@ let check_absent_variant env = (* Duplicate types of values in the environment *) (* XXX Should we do something about global type variables too? *) -let duplicate_ident_types caselist env = +let duplicate_ident_types half_typed_cases env = let caselist = - List.filter (fun {pc_lhs} -> may_contain_gadts pc_lhs) caselist in - Env.copy_types (all_idents_cases caselist) env + List.filter (fun { typed_pat; _ } -> + contains_gadt typed_pat + ) half_typed_cases + in + Env.make_copy_of_types (all_idents_cases caselist) env (* Getting proper location of already typed expressions. @@ -2863,6 +2895,10 @@ and type_expect_ pexp_desc = Pexp_match (sval, [Ast_helper.Exp.case spat sbody])} ty_expected_explained | Pexp_let(rec_flag, spat_sexp_list, sbody) -> + let existential_context = + if rec_flag = Recursive then In_rec + else if List.compare_length_with spat_sexp_list 1 > 0 then In_group + else With_attributes in let scp = match sexp.pexp_attributes, rec_flag with | [{txt="#default"},_], _ -> None @@ -2870,7 +2906,7 @@ and type_expect_ | _, Nonrecursive -> Some (Annot.Idef sbody.pexp_loc) in let (pat_exp_list, new_env, unpacks) = - type_let env rec_flag spat_sexp_list scp true in + type_let existential_context env rec_flag spat_sexp_list scp true in let body = type_expect new_env (wrap_unpacks sbody unpacks) ty_expected_explained in @@ -4632,10 +4668,6 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = let ty_arg = if (may_contain_gadts || erase_either) && not !Clflags.principal then correct_levels ty_arg else ty_arg - and ty_res, env = - if may_contain_gadts && not !Clflags.principal then - correct_levels ty_res, duplicate_ident_types caselist env - else ty_res, env in let rec is_var spat = match spat.ppat_desc with @@ -4674,9 +4706,9 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = let pattern_force = ref [] in (* Format.printf "@[%i %i@ %a@]@." lev (get_current_level()) Printtyp.raw_type_expr ty_arg; *) - let pat_env_list = + let half_typed_cases = List.map - (fun {pc_lhs; pc_guard; pc_rhs} -> + (fun ({pc_lhs; pc_guard; pc_rhs} as case) -> let loc = let open Location in match pc_guard with @@ -4690,7 +4722,7 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = end_def (); generalize_structure ty_arg; let expected_ty_arg = instance ty_arg in - let (pat, ext_env, force, unpacks) = + let (pat, ext_env, force, pvs, unpacks) = type_pattern ~lev env pc_lhs scope expected_ty_arg in pattern_force := force @ !pattern_force; @@ -4703,18 +4735,33 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = in (* Ensure that no ambivalent pattern type escapes its branch *) check_scope_escape pat.pat_loc env outer_level ty_arg; - (pat, ty_arg, (ext_env, unpacks))) + { typed_pat = pat; + pat_type_for_unif = ty_arg; + untyped_case = case; + branch_env = ext_env; + pat_vars = pvs; + unpacks; + contains_gadt = contains_gadt pat; } + ) caselist in + let patl = List.map (fun { typed_pat; _ } -> typed_pat) half_typed_cases in + let does_contain_gadt = + List.exists (fun { contains_gadt; _ } -> contains_gadt) half_typed_cases + in + let ty_res, duplicated_ident_types = + if does_contain_gadt && not !Clflags.principal then + correct_levels ty_res, duplicate_ident_types half_typed_cases env + else ty_res, duplicate_ident_types [] env + in (* Unify all cases (delayed to keep it order-free) *) let ty_arg' = newvar () in let unify_pats ty = - List.iter (fun (pat, pat_ty, _) -> + List.iter (fun { typed_pat = pat; pat_type_for_unif = pat_ty; _ } -> unify_pat_types pat.pat_loc env pat_ty ty - ) pat_env_list + ) half_typed_cases in unify_pats ty_arg'; (* Check for polymorphic variants to close *) - let patl = List.map (fun (pat, _, _) -> pat) pat_env_list in if List.exists has_variants patl then begin Parmatch.pressure_variants env patl; List.iter (iter_pattern finalize_variant) patl @@ -4733,8 +4780,21 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = (* type bodies *) let in_function = if List.length caselist = 1 then in_function else None in let cases = - List.map2 - (fun (pat, _, (ext_env, unpacks)) {pc_lhs = _; pc_guard; pc_rhs} -> + List.map + (fun { typed_pat = pat; branch_env = ext_env; pat_vars = pvs; unpacks; + untyped_case = {pc_lhs = _; pc_guard; pc_rhs}; + contains_gadt; _ } -> + let ext_env = + if contains_gadt then + Env.do_copy_types duplicated_ident_types ext_env + else + ext_env + in + let ext_env = + add_pattern_variables ext_env pvs + ~check:(fun s -> Warnings.Unused_var_strict s) + ~check_as:(fun s -> Warnings.Unused_var s) + in let sexp = wrap_unpacks pc_rhs unpacks in let ty_res' = if !Clflags.principal then begin @@ -4743,7 +4803,12 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = end_def (); generalize_structure ty; ty end - else if contains_gadt pat then correct_levels ty_res + else if contains_gadt then + (* Even though we've already done that, apparently we need to do it + again. + stdlib/camlinternalFormat.ml:2288 is an example of use of this + call to [correct_levels]... *) + correct_levels ty_res else ty_res in (* Format.printf "@[%i %i, ty_res' =@ %a@]@." lev (get_current_level()) Printtyp.raw_type_expr ty_res'; *) @@ -4763,16 +4828,16 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = c_rhs = {exp with exp_type = instance ty_res'} } ) - pat_env_list caselist + half_typed_cases in - if !Clflags.principal || may_contain_gadts then begin + if !Clflags.principal || does_contain_gadt then begin let ty_res' = instance ty_res in List.iter (fun c -> unify_exp env c.c_rhs ty_res') cases end; - (* We could check whether there actually is a GADT here instead of reusing - [has_constructor], but I'm not sure it's worth it. *) - let do_init = may_contain_gadts || needs_exhaust_check in + let do_init = does_contain_gadt || needs_exhaust_check in let lev = + (* if [may_contain_gadt] then [init_env] was already called, no need to do + it again. *) if do_init && not may_contain_gadts then init_env () else lev in let ty_arg_check = if do_init then @@ -4790,8 +4855,9 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = let lev = if do_init then init_env () else get_current_level () in - List.iter (fun (pat, _, (env, _)) -> check_absent_variant env pat) - pat_env_list; + List.iter (fun { typed_pat; branch_env; _ } -> + check_absent_variant branch_env typed_pat + ) half_typed_cases; check_unused ~lev env (instance ty_arg_check) cases ; if do_init then end_def (); Parmatch.check_ambiguous_bindings cases @@ -4810,8 +4876,10 @@ and type_cases ?in_function env ty_arg ty_res partial_flag loc caselist = (* Typing of let bindings *) -and type_let ?(check = fun s -> Warnings.Unused_var s) - ?(check_strict = fun s -> Warnings.Unused_var_strict s) +and type_let + ?(check = fun s -> Warnings.Unused_var s) + ?(check_strict = fun s -> Warnings.Unused_var_strict s) + existential_context env rec_flag spat_sexp_list scope allow = let open Ast_helper in begin_def(); @@ -4845,7 +4913,7 @@ and type_let ?(check = fun s -> Warnings.Unused_var s) spat_sexp_list in let nvs = List.map (fun _ -> newvar ()) spatl in let (pat_list, new_env, force, unpacks) = - type_pattern_list env spatl scope nvs allow in + type_pattern_list existential_context env spatl scope nvs allow in let attrs_list = List.map fst spatl in let is_recursive = (rec_flag = Recursive) in (* If recursive, first unify with an approximation of the expression *) @@ -5032,13 +5100,14 @@ let type_binding env rec_flag spat_sexp_list scope = type_let ~check:(fun s -> Warnings.Unused_value_declaration s) ~check_strict:(fun s -> Warnings.Unused_value_declaration s) + At_toplevel env rec_flag spat_sexp_list scope false in (pat_exp_list, new_env) -let type_let env rec_flag spat_sexp_list scope = +let type_let existential_ctx env rec_flag spat_sexp_list scope = let (pat_exp_list, new_env, _unpacks) = - type_let env rec_flag spat_sexp_list scope false in + type_let existential_ctx env rec_flag spat_sexp_list scope false in (pat_exp_list, new_env) (* Typing of toplevel expressions *) @@ -5312,9 +5381,37 @@ let report_error env ppf = function fprintf ppf "Recursive local constraint when unifying") (function ppf -> fprintf ppf "with") - | Unexpected_existential -> - fprintf ppf - "Unexpected existential" + | Unexpected_existential (reason, name, types) -> ( + begin match reason with + | In_class_args -> + fprintf ppf "Existential types are not allowed in class arguments,@ " + | In_class_def -> + fprintf ppf "Existential types are not allowed in bindings inside \ + class definition,@ " + | In_self_pattern -> + fprintf ppf "Existential types are not allowed in self patterns,@ " + | At_toplevel -> + fprintf ppf + "Existential types are not allowed in toplevel bindings,@ " + | In_group -> + fprintf ppf + "Existential types are not allowed in \"let ... and ...\" bindings,\ + @ " + | In_rec -> + fprintf ppf + "Existential types are not allowed in recursive bindings,@ " + | With_attributes -> + fprintf ppf + "Existential types are not allowed in presence of attributes,@ " + end; + try + let example = List.find (fun ty -> ty <> "$" ^ name) types in + fprintf ppf + "but this pattern introduces the existential type %s." example + with Not_found -> + fprintf ppf + "but the constructor %s introduces existential types." name + ) | Invalid_interval -> fprintf ppf "@[Only character intervals are supported in patterns.@]" | Invalid_for_loop_index -> diff --git a/typing/typecore.mli b/typing/typecore.mli index 30a0854a7a..65026080a9 100644 --- a/typing/typecore.mli +++ b/typing/typecore.mli @@ -55,13 +55,22 @@ val mk_expected: val is_nonexpansive: Typedtree.expression -> bool +type existential_restriction = + | At_toplevel (** no existential types at the toplevel *) + | In_group (** nor with [let ... and ...] *) + | In_rec (** or recursive definition *) + | With_attributes (** or [let[@any_attribute] = ...] *) + | In_class_args (** or in class arguments [class c (...) = ...] *) + | In_class_def (** or in [class c = let ... in ...] *) + | In_self_pattern (** or in self pattern *) + val type_binding: Env.t -> rec_flag -> Parsetree.value_binding list -> Annot.ident option -> Typedtree.value_binding list * Env.t val type_let: - Env.t -> rec_flag -> + existential_restriction -> Env.t -> rec_flag -> Parsetree.value_binding list -> Annot.ident option -> Typedtree.value_binding list * Env.t @@ -145,7 +154,7 @@ type error = | Cannot_infer_signature | Not_a_packed_module of type_expr | Recursive_local_constraint of (type_expr * type_expr) list - | Unexpected_existential + | Unexpected_existential of existential_restriction * string * string list | Invalid_interval | Invalid_for_loop_index | No_value_clauses diff --git a/typing/typedecl.ml b/typing/typedecl.ml index 5e4b9d5ad9..6a1a580a0b 100644 --- a/typing/typedecl.ml +++ b/typing/typedecl.ml @@ -1646,7 +1646,19 @@ let transl_exception env sext = | None -> () end; let newenv = Env.add_extension ~check:true ext.ext_id ext.ext_type env in - ext, newenv + ext, newenv + +let transl_type_exception env t = + Builtin_attributes.check_no_deprecated t.ptyexn_attributes; + let contructor, newenv = + Builtin_attributes.warning_scope t.ptyexn_attributes + (fun () -> + transl_exception env t.ptyexn_constructor + ) + in + {tyexn_constructor = contructor; + tyexn_attributes = t.ptyexn_attributes}, newenv + type native_repr_attribute = | Native_repr_attr_absent diff --git a/typing/typedecl.mli b/typing/typedecl.mli index 1c687cd04f..5465fb8bb6 100644 --- a/typing/typedecl.mli +++ b/typing/typedecl.mli @@ -23,8 +23,12 @@ val transl_type_decl: Typedtree.type_declaration list * Env.t val transl_exception: + Env.t -> Parsetree.extension_constructor -> + Typedtree.extension_constructor * Env.t + +val transl_type_exception: Env.t -> - Parsetree.extension_constructor -> Typedtree.extension_constructor * Env.t + Parsetree.type_exception -> Typedtree.type_exception * Env.t val transl_type_extension: bool -> Env.t -> Location.t -> Parsetree.type_extension -> diff --git a/typing/typedtree.ml b/typing/typedtree.ml index 4cc9964324..36b84ff5b2 100644 --- a/typing/typedtree.ml +++ b/typing/typedtree.ml @@ -226,7 +226,7 @@ and structure_item_desc = | Tstr_primitive of value_description | Tstr_type of rec_flag * type_declaration list | Tstr_typext of type_extension - | Tstr_exception of extension_constructor + | Tstr_exception of type_exception | Tstr_module of module_binding | Tstr_recmodule of module_binding list | Tstr_modtype of module_type_declaration @@ -301,7 +301,7 @@ and signature_item_desc = Tsig_value of value_description | Tsig_type of rec_flag * type_declaration list | Tsig_typext of type_extension - | Tsig_exception of extension_constructor + | Tsig_exception of type_exception | Tsig_module of module_declaration | Tsig_recmodule of module_declaration list | Tsig_modtype of module_type_declaration @@ -456,6 +456,12 @@ and type_extension = tyext_attributes: attribute list; } +and type_exception = + { + tyexn_constructor: extension_constructor; + tyexn_attributes: attribute list; + } + and extension_constructor = { ext_id: Ident.t; diff --git a/typing/typedtree.mli b/typing/typedtree.mli index 2e89ed5233..5774a5f8a9 100644 --- a/typing/typedtree.mli +++ b/typing/typedtree.mli @@ -347,7 +347,7 @@ and structure_item_desc = | Tstr_primitive of value_description | Tstr_type of rec_flag * type_declaration list | Tstr_typext of type_extension - | Tstr_exception of extension_constructor + | Tstr_exception of type_exception | Tstr_module of module_binding | Tstr_recmodule of module_binding list | Tstr_modtype of module_type_declaration @@ -421,7 +421,7 @@ and signature_item_desc = Tsig_value of value_description | Tsig_type of rec_flag * type_declaration list | Tsig_typext of type_extension - | Tsig_exception of extension_constructor + | Tsig_exception of type_exception | Tsig_module of module_declaration | Tsig_recmodule of module_declaration list | Tsig_modtype of module_type_declaration @@ -578,6 +578,12 @@ and type_extension = tyext_attributes: attributes; } +and type_exception = + { + tyexn_constructor: extension_constructor; + tyexn_attributes: attribute list; + } + and extension_constructor = { ext_id: Ident.t; diff --git a/typing/typedtreeIter.ml b/typing/typedtreeIter.ml index a3be8d3be5..fc9d9f9391 100644 --- a/typing/typedtreeIter.ml +++ b/typing/typedtreeIter.ml @@ -27,6 +27,7 @@ module type IteratorArgument = sig val enter_structure : structure -> unit val enter_value_description : value_description -> unit val enter_type_extension : type_extension -> unit + val enter_type_exception : type_exception -> unit val enter_extension_constructor : extension_constructor -> unit val enter_pattern : pattern -> unit val enter_expression : expression -> unit @@ -53,6 +54,7 @@ module type IteratorArgument = sig val leave_structure : structure -> unit val leave_value_description : value_description -> unit val leave_type_extension : type_extension -> unit + val leave_type_exception : type_exception -> unit val leave_extension_constructor : extension_constructor -> unit val leave_pattern : pattern -> unit val leave_expression : expression -> unit @@ -141,7 +143,7 @@ module MakeIterator(Iter : IteratorArgument) : sig | Tstr_primitive vd -> iter_value_description vd | Tstr_type (rf, list) -> iter_type_declarations rf list | Tstr_typext tyext -> iter_type_extension tyext - | Tstr_exception ext -> iter_extension_constructor ext + | Tstr_exception ext -> iter_type_exception ext | Tstr_module x -> iter_module_binding x | Tstr_recmodule list -> List.iter iter_module_binding list | Tstr_modtype mtd -> iter_module_type_declaration mtd @@ -219,6 +221,11 @@ module MakeIterator(Iter : IteratorArgument) : sig List.iter iter_extension_constructor tyext.tyext_constructors; Iter.leave_type_extension tyext + and iter_type_exception tyexn = + Iter.enter_type_exception tyexn; + iter_extension_constructor tyexn.tyexn_constructor; + Iter.leave_type_exception tyexn + and iter_pattern pat = Iter.enter_pattern pat; List.iter (fun (cstr, _, _attrs) -> match cstr with @@ -381,7 +388,7 @@ module MakeIterator(Iter : IteratorArgument) : sig | Tsig_type (rf, list) -> iter_type_declarations rf list | Tsig_exception ext -> - iter_extension_constructor ext + iter_type_exception ext | Tsig_typext tyext -> iter_type_extension tyext | Tsig_module md -> @@ -626,6 +633,7 @@ module DefaultIteratorArgument = struct let enter_structure _ = () let enter_value_description _ = () let enter_type_extension _ = () + let enter_type_exception _ = () let enter_extension_constructor _ = () let enter_pattern _ = () let enter_expression _ = () @@ -652,6 +660,7 @@ module DefaultIteratorArgument = struct let leave_structure _ = () let leave_value_description _ = () let leave_type_extension _ = () + let leave_type_exception _ = () let leave_extension_constructor _ = () let leave_pattern _ = () let leave_expression _ = () diff --git a/typing/typedtreeIter.mli b/typing/typedtreeIter.mli index 53aa54c120..2e2d0d05a1 100644 --- a/typing/typedtreeIter.mli +++ b/typing/typedtreeIter.mli @@ -21,6 +21,7 @@ module type IteratorArgument = sig val enter_structure : structure -> unit val enter_value_description : value_description -> unit val enter_type_extension : type_extension -> unit + val enter_type_exception : type_exception -> unit val enter_extension_constructor : extension_constructor -> unit val enter_pattern : pattern -> unit val enter_expression : expression -> unit @@ -47,6 +48,7 @@ module type IteratorArgument = sig val leave_structure : structure -> unit val leave_value_description : value_description -> unit val leave_type_extension : type_extension -> unit + val leave_type_exception : type_exception -> unit val leave_extension_constructor : extension_constructor -> unit val leave_pattern : pattern -> unit val leave_expression : expression -> unit diff --git a/typing/typedtreeMap.ml b/typing/typedtreeMap.ml index ccde8c03a4..3fd30dde5b 100644 --- a/typing/typedtreeMap.ml +++ b/typing/typedtreeMap.ml @@ -20,6 +20,7 @@ module type MapArgument = sig val enter_value_description : value_description -> value_description val enter_type_declaration : type_declaration -> type_declaration val enter_type_extension : type_extension -> type_extension + val enter_type_exception : type_exception -> type_exception val enter_extension_constructor : extension_constructor -> extension_constructor val enter_pattern : pattern -> pattern @@ -49,6 +50,7 @@ module type MapArgument = sig val leave_value_description : value_description -> value_description val leave_type_declaration : type_declaration -> type_declaration val leave_type_extension : type_extension -> type_extension + val leave_type_exception : type_exception -> type_exception val leave_extension_constructor : extension_constructor -> extension_constructor val leave_pattern : pattern -> pattern @@ -121,7 +123,7 @@ module MakeMap(Map : MapArgument) = struct | Tstr_typext tyext -> Tstr_typext (map_type_extension tyext) | Tstr_exception ext -> - Tstr_exception (map_extension_constructor ext) + Tstr_exception (map_type_exception ext) | Tstr_module x -> Tstr_module (map_module_binding x) | Tstr_recmodule list -> @@ -212,6 +214,13 @@ module MakeMap(Map : MapArgument) = struct Map.leave_type_extension { tyext with tyext_params = tyext_params; tyext_constructors = tyext_constructors } + and map_type_exception tyexn = + let tyexn = Map.enter_type_exception tyexn in + let tyexn_constructor = + map_extension_constructor tyexn.tyexn_constructor + in + Map.leave_type_exception { tyexn with tyexn_constructor = tyexn_constructor } + and map_extension_constructor ext = let ext = Map.enter_extension_constructor ext in let ext_kind = match ext.ext_kind with @@ -434,7 +443,7 @@ module MakeMap(Map : MapArgument) = struct | Tsig_typext tyext -> Tsig_typext (map_type_extension tyext) | Tsig_exception ext -> - Tsig_exception (map_extension_constructor ext) + Tsig_exception (map_type_exception ext) | Tsig_module md -> Tsig_module {md with md_type = map_module_type md.md_type} | Tsig_recmodule list -> @@ -680,6 +689,7 @@ module DefaultMapArgument = struct let enter_value_description t = t let enter_type_declaration t = t let enter_type_extension t = t + let enter_type_exception t = t let enter_extension_constructor t = t let enter_pattern t = t let enter_expression t = t @@ -707,6 +717,7 @@ module DefaultMapArgument = struct let leave_value_description t = t let leave_type_declaration t = t let leave_type_extension t = t + let leave_type_exception t = t let leave_extension_constructor t = t let leave_pattern t = t let leave_expression t = t diff --git a/typing/typedtreeMap.mli b/typing/typedtreeMap.mli index 7a826ae8d1..d1d6963e2e 100644 --- a/typing/typedtreeMap.mli +++ b/typing/typedtreeMap.mli @@ -20,6 +20,7 @@ module type MapArgument = sig val enter_value_description : value_description -> value_description val enter_type_declaration : type_declaration -> type_declaration val enter_type_extension : type_extension -> type_extension + val enter_type_exception : type_exception -> type_exception val enter_extension_constructor : extension_constructor -> extension_constructor val enter_pattern : pattern -> pattern @@ -49,6 +50,7 @@ module type MapArgument = sig val leave_value_description : value_description -> value_description val leave_type_declaration : type_declaration -> type_declaration val leave_type_extension : type_extension -> type_extension + val leave_type_exception : type_exception -> type_exception val leave_extension_constructor : extension_constructor -> extension_constructor val leave_pattern : pattern -> pattern diff --git a/typing/typemod.ml b/typing/typemod.ml index 1812e0899f..784a7e329e 100644 --- a/typing/typemod.ml +++ b/typing/typemod.ml @@ -838,11 +838,11 @@ and transl_signature env sg = Sig_typext(ext.ext_id, ext.ext_type, es)) constructors rem, final_env | Psig_exception sext -> - check_name check_typext names sext.pext_name; - let (ext, newenv) = Typedecl.transl_exception env sext in + check_name check_typext names sext.ptyexn_constructor.pext_name; + let (ext, newenv) = Typedecl.transl_type_exception env sext in let (trem, rem, final_env) = transl_sig newenv srem in mksig (Tsig_exception ext) env loc :: trem, - Sig_typext(ext.ext_id, ext.ext_type, Text_exception) :: rem, + Sig_typext(ext.tyexn_constructor.ext_id, ext.tyexn_constructor.ext_type, Text_exception) :: rem, final_env | Psig_module pmd -> check_name check_module names pmd.pmd_name; @@ -1508,10 +1508,10 @@ and type_structure ?(toplevel = false) funct_body anchor env sstr scope = tyext.tyext_constructors [], newenv) | Pstr_exception sext -> - check_name check_typext names sext.pext_name; - let (ext, newenv) = Typedecl.transl_exception env sext in + check_name check_typext names sext.ptyexn_constructor.pext_name; + let (ext, newenv) = Typedecl.transl_type_exception env sext in Tstr_exception ext, - [Sig_typext(ext.ext_id, ext.ext_type, Text_exception)], + [Sig_typext(ext.tyexn_constructor.ext_id, ext.tyexn_constructor.ext_type, Text_exception)], newenv | Pstr_module {pmb_name = name; pmb_expr = smodl; pmb_attributes = attrs; pmb_loc; diff --git a/typing/typeopt.ml b/typing/typeopt.ml index 145a15df5f..b318cc0962 100644 --- a/typing/typeopt.ml +++ b/typing/typeopt.ml @@ -50,6 +50,7 @@ let is_base_type env ty base_ty_path = | _ -> false let maybe_pointer_type env ty = + let ty = scrape_ty env ty in if Ctype.maybe_pointer_type env ty then Pointer else diff --git a/typing/untypeast.ml b/typing/untypeast.ml index 625c70ef62..ac854316b3 100644 --- a/typing/untypeast.ml +++ b/typing/untypeast.ml @@ -62,6 +62,7 @@ type mapper = { typ: mapper -> T.core_type -> core_type; type_declaration: mapper -> T.type_declaration -> type_declaration; type_extension: mapper -> T.type_extension -> type_extension; + type_exception: mapper -> T.type_exception -> type_exception; type_kind: mapper -> T.type_kind -> type_kind; value_binding: mapper -> T.value_binding -> value_binding; value_description: mapper -> T.value_description -> value_description; @@ -152,7 +153,7 @@ let structure_item sub item = | Tstr_typext tyext -> Pstr_typext (sub.type_extension sub tyext) | Tstr_exception ext -> - Pstr_exception (sub.extension_constructor sub ext) + Pstr_exception (sub.type_exception sub ext) | Tstr_module mb -> Pstr_module (sub.module_binding sub mb) | Tstr_recmodule list -> @@ -246,6 +247,11 @@ let type_extension sub tyext = (map_loc sub tyext.tyext_txt) (List.map (sub.extension_constructor sub) tyext.tyext_constructors) +let type_exception sub tyexn = + let attrs = sub.attributes sub tyexn.tyexn_attributes in + Te.mk_exception ~attrs + (sub.extension_constructor sub tyexn.tyexn_constructor) + let extension_constructor sub ext = let loc = sub.location sub ext.ext_loc in let attrs = sub.attributes sub ext.ext_attributes in @@ -501,7 +507,7 @@ let signature_item sub item = | Tsig_typext tyext -> Psig_typext (sub.type_extension sub tyext) | Tsig_exception ext -> - Psig_exception (sub.extension_constructor sub ext) + Psig_exception (sub.type_exception sub ext) | Tsig_module md -> Psig_module (sub.module_declaration sub md) | Tsig_recmodule list -> @@ -796,6 +802,7 @@ let default_mapper = type_kind = type_kind; typ = core_type; type_extension = type_extension; + type_exception = type_exception; extension_constructor = extension_constructor; value_description = value_description; pat = pattern; diff --git a/typing/untypeast.mli b/typing/untypeast.mli index 20a6668c92..f14a44f359 100644 --- a/typing/untypeast.mli +++ b/typing/untypeast.mli @@ -63,6 +63,7 @@ type mapper = { typ: mapper -> Typedtree.core_type -> core_type; type_declaration: mapper -> Typedtree.type_declaration -> type_declaration; type_extension: mapper -> Typedtree.type_extension -> type_extension; + type_exception: mapper -> Typedtree.type_exception -> type_exception; type_kind: mapper -> Typedtree.type_kind -> type_kind; value_binding: mapper -> Typedtree.value_binding -> value_binding; value_description: mapper -> Typedtree.value_description -> value_description; |