aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
AgeCommit message (Collapse)Author
2018-05-17Merge pull request #1810 from tomas-abrahamsson/bjorn/preprocessor-extensionsBjörn Gustavsson
Add ?OTP_RELEASE, -if and -elif to the preprocessor OTP-15087
2018-05-17Merge pull request #1817 from dgud/dgud/stdlib/string-opt-caseDan Gudmundsson
OTP-14988
2018-05-16Merge branch 'richcarl/eliminate_lib_module/PR-1786/OTP-15072'Hans Bolinder
* richcarl/eliminate_lib_module/PR-1786/OTP-15072: Fix minor issues Eliminate call to ct:get_progname() in ts_erl_config Use \n escape instead of integer 10 Move error formatting to erl_error.erl and delete lib.erl Move extended parse functions in lib.erl to erl_eval.erl Move lib:eval_str/1 into mod_esi.erl Remove lib:progname/0 Eliminate call to lib:progname/1 in slave.erl Add ct:get_progname/0 Remove lib:error_message/2 Remove lib:flush_receive/0 Remove lib:send/2 and lib:sendw/2 Move lib:nonl/1 into yecc.erl
2018-05-14Optimize string lowercase, uppercase and casefold for ASCII charactersDan Gudmundsson
2018-05-09Fix minor issuesRichard Carlsson
2018-05-09epp: Implement the -if and -elif preprocessor directivesBjörn Gustavsson
Libraries or applications that support more than one major release of OTP may need to use conditional compilation of Erlang source code. Here are few examples where it would be necessary or desirable: * To support a new data type or language feature only available in the latest major release (real-world examples: maps and the stacktrace syntax). * To avoid warnings for deprecated functions. * To avoid dialyzer warnings. Previously, to do conditional compilation, one would have to use a parse transform or some external tool such as 'autoconf'. To simplify conditional compilation, introduce the -if and -elif preprocessor directives, to allow code like this to be written: -if(?OTP_RELEASE =:= 21). %% Code that will only work in OTP 21. -else. %% Fallback code. -endif. What kind of expressions should be allowed after an -if? We certainly don't want to allow anything with a side effect, such as a '!' or a 'receive'. We also don't want it to be possible to call erlang:system_info/1, as that could make the code depedent on features of the run-time system that could change very easily (such as the number of schedulers). Requiring the expression to be a guard expression makes most sense. It is to explain in the documentation and easy for users to understand. For simplicity of implementation, only a single guard expression will be supported; that is, the ',' and ';' syntax for guards is not supported. To allow some useful conditions to be written, there is a special built-in function: defined(Symbol) tests whether the preprocessor symbol is defined, just like -ifdef. The reason for having this defined/1 is that the defined test can be combined with other tests, for example: 'defined(SOME_NAME) andalso ?OTP_RELEASE > 21'.
2018-05-08Merge pull request #1801 from dtip/update-global-name-specHans Bolinder
Update global name typespec
2018-05-07Merge pull request #1802 from michalmuskala/map-is-key-bifBjörn Gustavsson
Introduce is_map_key/2 guard BIF OTP-15037
2018-05-06epp: Add the pre-defined macro OTP_RELEASEBjörn Gustavsson
Add a new pre-defined macro called OTP_RELEASE that will expand to an integer being the OTP version. Thus, in OTP 19 the value will be the integer 19. The OTP_RELEASE macro is particularly useful in order to have different source code depending on new language features or new features in the type specification syntax. Those features are only introduced in major versions of OTP. To be truly useful, the -if preprocessor directive need to be implemented. That is the purpose of the next commit. Code that will need to work in both OTP 18 and OTP 19 can be structured in the following way: -ifdef(OTP_RELEASE). %% Code that only works in OTP 19 and later. -else. %% Code that will work in OTP 18. -endif.
2018-05-04Move error formatting to erl_error.erl and delete lib.erlRichard Carlsson
2018-05-04Move extended parse functions in lib.erl to erl_eval.erlRichard Carlsson
2018-05-04Move lib:eval_str/1 into mod_esi.erlRichard Carlsson
2018-05-04Remove lib:progname/0Richard Carlsson
2018-05-04Eliminate call to lib:progname/1 in slave.erlRichard Carlsson
2018-05-04Remove lib:error_message/2Richard Carlsson
2018-05-04Remove lib:flush_receive/0Richard Carlsson
2018-05-04Remove lib:send/2 and lib:sendw/2Richard Carlsson
2018-05-04Move lib:nonl/1 into yecc.erlRichard Carlsson
2018-04-29Introduce is_map_key/2 guard BIFMichał Muskała
This complements the `map_get/2` guard BIF introduced in #1784. Rationale. `map_get/2` allows accessing map fields in guards, but it might be problematic in more complex guard expressions, for example: foo(X) when map_get(a, X) =:= 1 or is_list(X) -> ... The `is_list/1` part of the guard could never succeed since the `map_get/2` guard would fail the whole guard expression. In this situation, this could be solved by using `;` instead of `or` to separate the guards, but it is not possible in every case. To solve this situation, this PR proposes a `is_map_key/2` guard that allows to check if a map has key inside a guard before trying to access that key. When combined with `is_map/1` this allows to construct a purely boolean guard expression testing a value of a key in a map. Implementation. Given the use case motivating the introduction of this function, the PR contains compiler optimisations that produce optimial code for the following guard expression: foo(X) when is_map(X) and is_map_key(a, X) and map_get(a, X) =:= 1 -> ok; foo(_) -> error. Given all three tests share the failure label, the `is_map_key/2` and `is_map/2` tests are optimised away. As with `map_get/2` the `is_map_key/2` BIF is allowed in match specs.
2018-04-27Update global name typespecDaniel Tipping
2018-04-27Merge branch 'siri/kernel/logger/OTP-13295'Siri Hansen
* siri/kernel/logger/OTP-13295: Add documentation of the built-in logger handlers Catch badarg in logger:get_format_depth/0 Add chars_limit option to logger_formatter Don't kill logger process until all other processes are dead Set call timeout for logger_server to infinity Update primary bootstrap Test cuddle for logger Update cth_log_redirect to a logger handler Start using logger internally in kernel and stdlib Remove error_logger process and add logger process Add logger
2018-04-27Merge branch 'hasse/stdlib/rfc3339_datetime/OTP-14764'Hans Bolinder
* hasse/stdlib/rfc3339_datetime/OTP-14764: stdlib: Add RFC 3339 functions to module calendar
2018-04-26Update appups in kernel, stdlib and sasl for OTP-21.0Siri Hansen
2018-04-26[stdlib/sys]: install one debug function more times (#1781)Pouriya
Allow installing multiple instances of sys debug function This commit solves a bug which allowed installing {Fun,State} as sys debug function even if Fun was already installed. This happened in the case when the current State of the debug fun was undefined. Also, the new format {Id,Fun,State} of debug functions can be installed, allowing multiple instances of the same fun.
2018-04-26Merge pull request #1759 from sunboshan/sys-fixSiri Hansen
[stdlib/sys.erl] Fix sys module's debug statistics not including the out message count when using gen_server:call/2. OTP-15047
2018-04-26stdlib: Add RFC 3339 functions to module calendarHans Bolinder
Functions for converting between RFC 3339 strings and system time are added. Options are lists, but we are considering using maps instead. If we change, it will happen after Erlang/OTP 21.0-rc1 is released.
2018-04-26Merge branch 'hasse/stdlib/calendar_systemtime/OTP-13413'Hans Bolinder
* hasse/stdlib/calendar_systemtime/OTP-13413: stdlib: Add system time functions to module calendar
2018-04-26Start using logger internally in kernel and stdlibSiri Hansen
2018-04-25stdlib: Modify the printing of map associations with wWpPHans Bolinder
Use the same depth for all (printed) elements of a map. Since the order of keys can vary when printing a map--maps:iterator/1 and maps:next/1 are used--it is more consistent to print all associations with the same depth. If the associations printed are limited by the depth, the selection of associations is arbitrary, as before.
2018-04-25stdlib: Introduce characters limit of formated stringsHans Bolinder
Inspiration from module lager_format. Also some improvements of Unicode handling. io_lib:format/3 and io_lib:fwrite/3 are new functions. The representation of the options is a list, but we are considering using a map instead. If we change, it will happen after Erlang/OTP 21.0-rc1 is released.
2018-04-25stdlib: Modify ~w/~W when number of characters is limitedHans Bolinder
A bug fix: limited maps end with "...", not "...=>...". A modification: wW separate pairs with " => ", not "=>". When the output is limited on number of characters, the term is balanced by wW the same way as is done with pP (see commit bc38638).
2018-04-25stdlib: io_lib{_pretty}: Avoid tuple_to_list when possibleHans Bolinder
2018-04-25stdlib: Introduce characters limit of formatted stringsHans Bolinder
The name of the io_lib_pretty:print/2 option 'max_chars' is changed to 'line_max_chars' (used by module shell only). The new option for limiting the number of returned characters of io_lib_pretty:print() is called 'chars_limit'.
2018-04-25Merge branch 'hasse/stdlib/map_guards_shell/OTP-15035/ERL-613'Hans Bolinder
* hasse/stdlib/map_guards_shell/OTP-15035/ERL-613: erts: Correct abstract format doc regarding map creation stdlib: Correct the linter's check of map guard expressions
2018-04-25Merge branch 'map-get-bif' of git://github.com/michalmuskala/otpBjörn Gustavsson
* 'map-get-bif' of git://github.com/michalmuskala/otp: Introduce map_get guard-safe function OTP-15037
2018-04-24stdlib: Correct the linter's check of map guard expressionsHans Bolinder
The check is used by evaluating modules such as erl_eval. An example: "if map_size(#{}) =:= 0 -> ok end.".
2018-04-24Merge branch 'raimo/stdlib/gen_statem-dev/OTP-14015'Raimo Niskanen
* raimo/stdlib/gen_statem-dev/OTP-14015: Fix after feedback Improve pointer to User's Guide Fix after feedback on 'When to use' Add a 'When to use' section Fix timeout parsing and doc feedback Improve doc, change images to .svg erl_docgen: Implement width in image tag Update User's Guide and pointers to it Improve error reasons from state enter call
2018-04-24Introduce map_get guard-safe functionMichał Muskała
Rationale Today all compound data types except for maps can be deconstructed in guards. For tuples we have `element/2` and for lists `hd/1` and `tl/1`. Maps are completely opaque to guards. This means matching on maps can't be abstracted into macros, which is often done with repetitive guards. It also means that maps have to be always selected whole from ETS tables, even when only one field would be enough, which creates a potential efficiency issue. This PR introduces an `erlang:map_get/2` guard-safe function that allows extracting a map field in guard. An alternative to this function would be to introduce the syntax for extracting a value from a map that was planned in the original EEP: `Map#{Key}`. Even outside of guards, since this function is a guard-BIF it is more efficient than using `maps:get/2` (since it does not need to set up the stack), and more convenient from pattern matching on the map (compare: `#{key := Value} = Map, Value` to `map_get(key, Map)`). Performance considerations A common concern against adding this function is the notion that "guards have to be fast" and ideally execute in constant time. While there are some counterexamples (`length/1`), what is more important is the fact that adding those functions does not change in any way the time complexity of pattern matching - it's already possible to match on map fields today directly in patterns - adding this ability to guards will niether slow down or speed up the execution, it will only make certain programs more convenient to write. This first version is very naive and does not perform any optimizations.
2018-04-23Fix sys's debug statistics.Boshan Sun
Currently, in sys:stat/2, the message out only count for system events with format {out, Msg, To}. However, the gen_server:reply/5 will call sys:handle_debug/4 with format {out, Reply, To, State}. That will make the message out count fail to pattern matching. Also update sys_SUITE.erl and relevant docs.
2018-04-21stdlib: Add system time functions to module calendarHans Bolinder
2018-04-16Remove warnings for improper use of erlang:get_stacktrace/0Björn Gustavsson
Those warnings don't make sense any more since erlang:get_stacktrace/0 is now deprecated.
2018-04-16Deprecate erlang:get_stacktrace/0Björn Gustavsson
2018-04-12Fix timeout parsing and doc feedbackRaimo Niskanen
2018-04-04Merge pull request #1725 from michalmuskala/fun-literalsBjörn Gustavsson
Compile external fun expressions to literals OTP-15003
2018-03-27Merge branch 'dgud/revert-string-depr'Dan Gudmundsson
* dgud/revert-string-depr: Revert "Deprecate old string functions"
2018-03-26Compile external fun expressions to literalsMichał Muskała
The expressions fun M:F/A, when all elements are literals are also treated as a literal. Since they have consistent representation and don't depend on the code currently loaded in the VM, this is safe. This can provide significant performance improvements in code using such functions extensively - a full function call to erlang:make_fun/3 is replaced by a single move instruction and no register shuffling or saving registers to stack is necessary. Additionally, compound data types that contain such external functions as elements can be treated as literals too. The commit also changes the representation of external funs to be a valid Erlang syntax and adds support for literal external funs to core Erlang.
2018-03-26Merge branch 'raimo/type-posix-0-overhaul/ERL_550/OTP-14019'Raimo Niskanen
* raimo/type-posix-0-overhaul/ERL_550/OTP-14019: Update types for posix error codes
2018-03-26Update types for posix error codesRaimo Niskanen
I have read the man pages for most socket and file operations on recent Linux, FreeBSD, OpenBSD and Solaris 10 and noted the possible error codes. Which error codes that are possible for file operations have been updated in file:posix/0. Error codes for socket operations in inet:posix/0. The latter refers to the former so it is a superset, assuming that e.g sendfile and AF_UNIX socket operations could cause socket operations to return any file error code. That is not entirely true, but could be, especially in the future. Added to file:posix/0 are: ebadmsg edeadlk edeadlock eftype emultihop enobufs enolck enolink enosr enostr enosys eopnotsupp eoverflow erange etxtbsy Added to inet:posix/0 are all but: exbadport exbadseq file:posix() These are still possible according to erl_posix_str.c, but are not in file:posix/0 nor in inet:posix/0, and many of them are not file nor inet related, but some might be: e2big eadv ealign ebade ebadfd ebadr ebadrpc ebadrqc ebadslt ebfont echild echrng ecomm edirty edom edotdot eduppkg eidrm einit eisnam elbin el2hlt el2nsync el3hlt el3rst elibacc elibbad elibexec elibmax elibscn elnrng enavail enet enoano enocsi enodata enoexec enonet enosym enotempty enotnam enotuniq eproclim eprocunavail eprogmismatch eprogunavail erefused eremchg eremdev eremote eremoteio eremoterelease erpcmismatch erremote eshutdown esrmnt esuccesss etime etoomanyrefs euclean eunatch eusers eversion exfull sysnotready vernotsupported ediscon enomore ecancelled einvalidproctable einvalidprovider eproviderfailedinit syscallfailure service_not_found type_not_found e_no_more e_cancelled unknown
2018-03-26Merge pull request #1703 from juhlig/masterHans Bolinder
[ERL-557] add is_empty/1 to sets and ordsets OTP-14996, ERL-557, PR-1703
2018-03-22Revert "Deprecate old string functions"Dan Gudmundsson
It has been decided that it was to early to deprecate the old string functions. This partially reverts commit ccb3f7f9768d3c28783c771df47eec1829e51802.