Skip to content

Commit 7fc4265

Browse files
committed
Merge pull request ocaml#316 from alainfrisch/deprecated_unit
Allowing to mark compilation units and sub-modules as deprecated
2 parents fa4a2d3 + 0121d05 commit 7fc4265

17 files changed

+270
-116
lines changed

Changes

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ Compilers:
9898
(Pierre Chambart, Xavier Leroy)
9999
- PR#7022, GPR#259: unbox float and boxed ints earlier, avoid second pass
100100
(Alain Frisch)
101+
- PR#7064, GPR#316: allowing to mark compilation units and sub-modules as
102+
deprecated (Alain Frisch)
101103
- GPR#263: improve code generation for if-equivalents of (&&) and (||)
102104
(Pierre Chambart)
103105
- GPR#271: Fix incorrect mutability flag when records are built using "with"

driver/compile.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ let interface ppf sourcefile outputprefix =
4242
Typecore.force_delayed_checks ();
4343
Warnings.check_fatal ();
4444
if not !Clflags.print_types then begin
45-
let sg = Env.save_signature sg modulename (outputprefix ^ ".cmi") in
45+
let deprecated = Typetexp.deprecated_of_sig ast in
46+
let sg = Env.save_signature ~deprecated sg modulename (outputprefix ^ ".cmi") in
4647
Typemod.save_signature modulename tsg outputprefix sourcefile
4748
initial_env sg ;
4849
end

driver/optcompile.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ let interface ppf sourcefile outputprefix =
4343
Typecore.force_delayed_checks ();
4444
Warnings.check_fatal ();
4545
if not !Clflags.print_types then begin
46-
let sg = Env.save_signature sg modulename (outputprefix ^ ".cmi") in
46+
let deprecated = Typetexp.deprecated_of_sig ast in
47+
let sg = Env.save_signature ~deprecated sg modulename (outputprefix ^ ".cmi") in
4748
Typemod.save_signature modulename tsg outputprefix sourcefile
4849
initial_env sg ;
4950
end

manual/manual/refman/exten.etex

+6-1
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,11 @@ Some attributes are understood by the type-checker:
14631463
Can be applied to most kind of items in signatures or
14641464
structures. When the element is later referenced, a warning (3) is
14651465
triggered. If the payload of the attribute is a string literal,
1466-
the warning message includes this text.
1466+
the warning message includes this text. It is also possible
1467+
to use this ``ocaml.deprecated'' as a floating attribute
1468+
on top of an ``.mli'' file (i.e. before any other non-attribute
1469+
item) or on top of an ``.ml'' file without a corresponding
1470+
interface; this marks the unit itself as being deprecated.
14671471
\item
14681472
``ocaml.ppwarning'' or ``ppwarning'', in any context, with
14691473
a string literal payload. The text is reported as warning (22)
@@ -1478,6 +1482,7 @@ module X = struct
14781482
[@@@warning "+9"] (* locally enable warning 9 in this structure *)
14791483
...
14801484
end
1485+
[@@deprecated "Please is module 'Y' instead."]
14811486

14821487
let x = begin[@warning "+9] ... end in ....
14831488

testsuite/tests/warnings/Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212

1313
BASEDIR=../..
1414
FLAGS=-w A
15-
EXECNAME=./program
1615

1716
run-all:
17+
@$(OCAMLC) $(FLAGS) -c deprecated_module.mli
1818
@for file in *.ml; do \
1919
printf " ... testing '$$file':"; \
2020
F="`basename $$file .ml`"; \
21-
$(OCAMLC) $(FLAGS) -o $(EXECNAME) $$file 2>$$F.result; \
21+
$(OCAMLC) $(FLAGS) -c $$file 2>$$F.result; \
2222
$(DIFF) $$F.reference $$F.result >/dev/null \
2323
&& echo " => passed" || echo " => failed"; \
2424
done;
2525
@for file in *.opt.ml; do \
26-
printf " ... testing '$$file':"; \
26+
printf " ... testing '$$file' with ocamlopt:"; \
2727
F="`basename $$file .ml`"; \
28-
$(OCAMLOPT) $(FLAGS) -o $(EXECNAME) $$file 2>$$F.opt_result; \
28+
$(OCAMLOPT) $(FLAGS) -c $$file 2>$$F.opt_result; \
2929
$(DIFF) $$F.opt_reference $$F.opt_result >/dev/null \
3030
&& echo " => passed" || echo " => failed"; \
3131
done;
3232

3333
promote: defaultpromote
3434

3535
clean: defaultclean
36-
@rm -f *.result $(EXECNAME)
36+
@rm -f *.result
3737

3838
include $(BASEDIR)/makefiles/Makefile.common
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module M = struct
2+
type t = int
3+
4+
let x = 10
5+
end
6+
[@@ocaml.deprecated]
7+
8+
let _ = M.x
9+
include M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[@@@ocaml.deprecated {|
2+
As you could guess, Deprecated_module is deprecated.
3+
Please use something else!
4+
|} ]
5+
6+
module M: sig
7+
val x: int
8+
[@@ocaml.deprecated]
9+
10+
type t
11+
[@@ocaml.deprecated]
12+
end
13+
[@@ocaml.deprecated]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
File "deprecated_module.ml", line 8, characters 8-11:
2+
Warning 3: deprecated: module M
3+
File "deprecated_module.ml", line 9, characters 8-9:
4+
Warning 3: deprecated: module M
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
open Deprecated_module
2+
3+
type s = M.t
4+
5+
open M
6+
let _ = x

testsuite/tests/warnings/deprecated_module_use.reference

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
File "deprecated_module_use.ml", line 1, characters 5-22:
2+
Warning 3: deprecated: module Deprecated_module
3+
4+
As you could guess, Deprecated_module is deprecated.
5+
Please use something else!
6+
7+
File "deprecated_module_use.ml", line 3, characters 9-12:
8+
Warning 3: deprecated: module Deprecated_module.M
9+
File "deprecated_module_use.ml", line 3, characters 9-12:
10+
Warning 3: deprecated: Deprecated_module.M.t
11+
File "deprecated_module_use.ml", line 5, characters 5-6:
12+
Warning 3: deprecated: module Deprecated_module.M
13+
File "deprecated_module_use.ml", line 6, characters 8-9:
14+
Warning 3: deprecated: Deprecated_module.M.x

typing/cmi_format.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
(* *)
1111
(***********************************************************************)
1212

13-
type pers_flags = Rectypes
13+
type pers_flags =
14+
| Rectypes
15+
| Deprecated of string
1416

1517
type error =
1618
Not_an_interface of string

typing/cmi_format.mli

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
(* *)
1111
(***********************************************************************)
1212

13-
type pers_flags = Rectypes
13+
type pers_flags =
14+
| Rectypes
15+
| Deprecated of string
1416

1517
type cmi_infos = {
1618
cmi_name : string;

0 commit comments

Comments
 (0)