summaryrefslogtreecommitdiff
path: root/HOWTO/DEPRECATE.md
blob: e292ca4c7602c3cde904f3339f603c958f91378d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Deprecate

This HOWTO shows how to deprecate functionality from Erlang/OTP.

When adding a new *deprecation* or *removal* warning you need to add an attribute to
the module in question and update [$ERL_TOP/system/doc/general_info/DEPRECATIONS][1]
with information about when the deprecation was added.

After changing or adding an attribute, and updating the [`DEPRECATIONS`][1],
you need to update the internal state by running:

    $ ./otp_build update_deprecations

This will update the documentation and the central list of deprecated and removed
interfaces ([`otp_internal.erl`][2]).

## Attribute format

To mark a function/type as deprecated or removed, point out its name and arity
together with a suggestion on what the user should do instead:

    -deprecated([{now,0,
                  "see the \"Time and Time Correction in Erlang\" "
                  "chapter of the ERTS User's Guide for more information"}]).
    
    -deprecated([{cmac, 3, "use crypto:mac/4 instead"},
                 {cmac, 4, "use crypto:macN/5 instead"}]).
    
    -removed([{md5_mac,2,"use crypto:hmac/3 instead"},
              {md5_mac_96,2,"use crypto:hmac/4 instead"}]).
    
    -deprecated_type([{gadget,1,"use widget/1 instead"}]).
    
    -removed_type([{column,0,"use erl_anno:column() instead"},
                   {line,0,"use erl_anno:line() instead"},
                   {location,0,"use erl_anno:location() instead"}]).

Wildcards can be used to match all names and/or arities:

    -removed([{rsa_sign,'_',"use crypto:sign/4 instead"},
              {rsa_verify,'_',"use crypto:verify/5 instead"}]).
    
    -deprecated([{next_iv, '_',"see the 'New and Old API' chapter of the CRYPTO User's guide"}]).
    
    -deprecated([{'_','_',"use the 'rand' module instead"}]).
    
    -deprecated_type([{grunka,'_',"use frobnitz/1,2 instead"}]).

You can also use the `Name/Arity` shorthand for all of these variants, e.g.
`-deprecated([f/1])`, which will result in a generic description to the effect of
"see the documentation for details."

Note that it is not possible to warn about a module that no longer exists.
This is to prevent later namespace clashes from raising warnings, like the ones
we had when the long-removed `net` module reappeared in the socket NIF.
"Removed" modules should instead have their contents replaced by
`-removed()` attributes until there's no longer any point in warning
about their use.

## The DEPRECATIONS file

The [$ERL_TOP/system/doc/general_info/DEPRECATIONS][1] file contains additional
information about each deprecated function, namely in what release it was deprecated
and optionally in what release it will be removed. The information in this file will
be used to generate the [Deprecations](http://erlang.org/doc/general_info/deprecations.html),
[Scheduled for Removal](http://erlang.org/doc/general_info/scheduled_for_removal.html),
and [Removed Functionality](http://erlang.org/doc/general_info/removed.html),
pages in the documentation.

Here is how the entry for `erlang:now/0` that was deprecated in OTP 18 looks like:

    erlang:now/0 since=18

Here is an example of a function that was deprecated in OTP 23 and is scheduled for removal in OTP 25:

    filename:safe_relative_path/1 since=23 remove=25

After removing a function it's important to keep its line in the DEPRECATIONS
file for as long as we wish to raise warnings about it. Should a removal be
postponed, the corresponding `remove` attribute must be bumped accordingly.

 [1]: ../system/doc/general_info/DEPRECATIONS
 [2]: ../lib/stdlib/src/otp_internal.erl