forked from erlang/otp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherlang.erl
12735 lines (10742 loc) · 445 KB
/
erlang.erl
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 1996-2024. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%
%% %CopyrightEnd%
%%
-module(erlang).
-moduledoc """
The Erlang BIFs and predefined types.
By convention, most [Built-In Functions](`e:system:ref_man_functions.md#built-in-functions-bifs`)
(BIFs) and all [predefined types](`e:system:typespec.md#predefined`) are included
in this module. Some of the BIFs and all of the predefined types are viewed more
or less as part of the Erlang programming language and are _auto-imported_.
Thus, it is not necessary to specify the module name. For example, the calls
[`atom_to_list(erlang)`](`atom_to_list/1`) and [`erlang:atom_to_list(erlang)`](`atom_to_list/1`)
are identical.
Auto-imported BIFs are annotated with `auto-imported` and predefined types are
annotated with `predefined`.
Some auto-imported BIFs are also allowed in [guard expression](`e:system:expressions.md#guard-expressions`).
Such BIFs are annoted with both `auto-imported` and `guard-bif`.
BIFs can fail for various reasons. All BIFs fail with reason `badarg` if they
are called with arguments of an incorrect type. The other reasons are described
in the description of each individual BIF.
""".
-export([apply/2,apply/3,spawn/4,spawn_link/4,
spawn_monitor/1,spawn_monitor/2,
spawn_monitor/3,spawn_monitor/4,
spawn_opt/2,spawn_opt/3,spawn_opt/4,spawn_opt/5,
spawn_request/1, spawn_request/2,
spawn_request/3, spawn_request/4, spawn_request/5,
spawn_request_abandon/1, disconnect_node/1]).
-export([spawn/1, spawn_link/1, spawn/2, spawn_link/2]).
-export([yield/0]).
-export([fun_info/1]).
-export([send_nosuspend/2, send_nosuspend/3]).
-export([localtime_to_universaltime/1]).
-export([suspend_process/1]).
-export([min/2, max/2]).
-export([dmonitor_node/3]).
-export([delay_trap/2]).
-export([set_cookie/1, set_cookie/2, get_cookie/0, get_cookie/1]).
-export([nodes/0, nodes/1, nodes/2]).
-export([integer_to_list/2]).
-export([integer_to_binary/2]).
-export([set_cpu_topology/1, format_cpu_topology/1]).
-export([memory/0, memory/1]).
-export([alloc_info/1, alloc_sizes/1]).
-export([gather_gc_info_result/1]).
-export([dist_ctrl_input_handler/2,
dist_ctrl_put_data/2,
dist_ctrl_get_data/1,
dist_ctrl_get_data_notification/1,
dist_ctrl_get_opt/2,
dist_ctrl_set_opt/3,
dist_get_stat/1]).
-deprecated([{now,0,
"see the \"Time and Time Correction in Erlang\" "
"chapter of the ERTS User's Guide for more information"}]).
-deprecated([{phash,2, "use erlang:phash2/2 instead"}]).
-removed([{hash,2,"use erlang:phash2/2 instead"}]).
-removed([{get_stacktrace,0,
"use the new try/catch syntax for retrieving the "
"stack backtrace"}]).
%% Get rid of autoimports of spawn to avoid clashes with ourselves.
-compile({no_auto_import,[spawn_link/1]}).
-compile({no_auto_import,[spawn_link/4]}).
-compile({no_auto_import,[spawn_opt/2]}).
-compile({no_auto_import,[spawn_opt/4]}).
-compile({no_auto_import,[spawn_opt/5]}).
%% We must inline these functions so that the stacktrace points to
%% the correct function.
-compile({inline, [badarg_with_info/1,error_with_info/2,
error_with_inherited_info/3,badarg_with_cause/2]}).
-compile(no_auto_import_types).
%% Built-in datatypes
-doc "All possible Erlang terms. Synonym for `t:term/0`.".
-type any() :: any().
-doc "The arity of a function or type.".
-type arity() :: arity().
-doc "An Erlang [atom](`e:system:data_types.md#atom`).".
-type atom() :: atom().
-doc """
An Erlang [binary](`e:system:data_types.md#bit-strings-and-binaries`), that is,
a bitstring with a size divisible by 8.
""".
-type binary() :: <<_:_*8>>.
-doc "An Erlang [bitstring](`e:system:data_types.md#bit-strings-and-binaries`).".
-type bitstring() :: <<_:_*1>>.
-doc false.
-type bool() :: boolean().
-doc "A [boolean](`e:system:data_types.md#boolean`) value.".
-type boolean() :: true | false.
-doc "A byte of data represented by an integer.".
-type byte() :: 0..255.
-doc "An ASCII character or a `m:unicode` codepoint presented by an integer.".
-type char() :: 0..16#10FFFF.
-doc "The [dynamic](`e:system:typespec.md#dynamic`) type, which represents a statically unknown type".
-type dynamic() :: dynamic().
-doc "An Erlang [float](`e:system:data_types.md#number`).".
-type float() :: float().
-doc "An Erlang [fun](`e:system:data_types.md#fun`).".
-type function() :: fun().
-doc """
An unique identifier for some entity, for example a
[process](`e:system:ref_man_processes.md`), [port](`e:system:ports.md#ports`) or
[monitor](`monitor/2`).
""".
-type identifier() :: pid() | port() | reference().
-doc "An Erlang [integer](`e:system:data_types.md#number`).".
-type integer() :: integer().
-doc """
A binary or list containing bytes and/or iodata.
This datatype is used to represent data that is meant to be output using
any I/O module. For example: `file:write/2` or `gen_tcp:send/2`.
To convert an `t:iodata/0` term to `t:binary/0` you can use
[iolist_to_binary/2](`iolist_to_binary/1`). To transcode a `t:string/0` or
`t:unicode:chardata/0` to `t:iodata/0` you can use `unicode:characters_to_binary/1`.
""".
-type iodata() :: iolist() | binary().
-doc """
A list containing bytes and/or iodata.
This datatype is used to represent data that is meant to be output using any
I/O module. For example: `file:write/2` or `gen_tcp:send/2`.
In most use cases you want to use `t:iodata/0` instead of this type.
""".
-type iolist() :: maybe_improper_list(byte() | binary() | iolist(), binary() | []).
-doc "An Erlang [list](`e:system:data_types.md#list`) containing terms of any type.".
-type list() :: [any()].
-doc """
An Erlang [list](`e:system:data_types.md#list`) containing terms of the type
`ContentType`.
""".
-type list(ContentType) :: [ContentType].
-doc """
An Erlang [map](`e:system:data_types.md#map`) containing any number of key and
value associations.
""".
-type map() :: #{ any() => any() }.
-doc """
An Erlang [list](`e:system:data_types.md#list`) that is not guaranteed to end
with a [`[]`](`t:nil/0`), and where the list elements can be of any type.
""".
-type maybe_improper_list() :: maybe_improper_list(any(), any()).
-doc """
An Erlang [list](`e:system:data_types.md#list`), that is not guaranteed to end
with a [`[]`](`t:nil/0`), and where the list elements are of the type
`ContentType`.
""".
-type maybe_improper_list(ContentType, TerminationType) ::
maybe_improper_list(ContentType, TerminationType).
-doc "A three-tuple representing a `Module:Function/Arity` function signature.".
-type mfa() :: {module(),atom(),arity()}.
-doc "An Erlang module represented by an atom.".
-type module() :: atom().
-doc "A negative integer.".
-type neg_integer() :: neg_integer().
-doc "The empty `t:list/0`.".
-type nil() :: [].
-doc """
The type used to show that a function will _never_ return a value, that is it
will _always_ throw an exception.
""".
-type no_return() :: none().
-doc "An Erlang [node](`e:system:distributed.md#nodes`) represented by an atom.".
-type node() :: atom().
-doc "A non-negative integer, that is any positive integer or 0.".
-type non_neg_integer() :: non_neg_integer().
-doc """
This type is used to show that a function will _never_ return a value; that is
it will _always_ throw an exception.
In a spec, use `t:no_return/0` for the sake of clarity.
""".
-type none() :: none().
-doc "A `t:binary/0` that contains some data.".
-type nonempty_binary() :: <<_:8, _:_*8>>.
-doc "A `t:bitstring/0` that contains some data.".
-type nonempty_bitstring() :: <<_:1, _:_*1>>.
-doc "A [maybe_improper_list/2](`t:maybe_improper_list/0`) that contains some items.".
-type nonempty_improper_list(ContentType, TerminationType) ::
nonempty_improper_list(ContentType, TerminationType).
-doc "A `t:list/0` that contains some items.".
-type nonempty_list() :: nonempty_list(any()).
-doc "A [list(ContentType)](`t:list/0`) that contains some items.".
-type nonempty_list(ContentType) :: [ContentType, ...].
-doc "A `t:maybe_improper_list/0` that contains some items.".
-type nonempty_maybe_improper_list() :: nonempty_maybe_improper_list(any(), any()).
-doc """
A [maybe_improper_list(ContentType, TerminationType)](`t:maybe_improper_list/0`)
that contains some items.
""".
-type nonempty_maybe_improper_list(ContentType, TerminationType) :: nonempty_maybe_improper_list(ContentType, TerminationType).
-doc "A `t:string/0` that contains some characters.".
-type nonempty_string() :: nonempty_list(char()).
-doc "An Erlang [number](`e:system:data_types.md#number`).".
-type number() :: integer() | float().
-doc "An Erlang [process identifier](`e:system:data_types.md#pid`).".
-type pid() :: pid().
-doc "An Erlang [port identifier](`e:system:data_types.md#port-identifier`).".
-type port() :: port().
-doc "An integer greater than zero.".
-type pos_integer() :: pos_integer().
-doc "An Erlang [reference](`e:system:data_types.md#reference`).".
-type reference() :: reference().
-doc """
A character string represented by a list of ASCII characters or unicode
codepoints.
""".
-type string() :: [char()].
-doc "All possible Erlang terms. Synonym for `t:any/0`.".
-type term() :: any().
-doc """
A timeout value that can be passed to a
[receive expression](`e:system:expressions.md#receive`).
""".
-type timeout() :: 'infinity' | non_neg_integer().
-doc "An Erlang [tuple](`e:system:data_types.md#tuple`).".
-type tuple() :: tuple().
-export_type([any/0, arity/0, atom/0, binary/0, bitstring/0, bool/0, boolean/0, byte/0,
char/0, dynamic/0, float/0, function/0, identifier/0, integer/0, iodata/0, iolist/0,
list/0, list/1, map/0, maybe_improper_list/0, maybe_improper_list/2, mfa/0,
module/0, neg_integer/0, nil/0, no_return/0, node/0, non_neg_integer/0,
none/0, nonempty_binary/0, nonempty_bitstring/0, nonempty_improper_list/2,
nonempty_list/0, nonempty_list/1, nonempty_maybe_improper_list/0,
nonempty_maybe_improper_list/2, nonempty_string/0, number/0, pid/0,
port/0, pos_integer/0, reference/0, string/0, term/0, timeout/0,
tuple/0]).
%% Datatypes that need an erlang: prefix
-export_type([timestamp/0]).
-export_type([time_unit/0]).
-export_type([deprecated_time_unit/0]).
-export_type([spawn_opt_option/0]).
-export_type([priority_level/0]).
-export_type([max_heap_size/0]).
-export_type([message_queue_data/0]).
-export_type([monitor_option/0]).
-export_type([stacktrace/0]).
-type stacktrace_extrainfo() ::
{line, pos_integer()} |
{file, unicode:chardata()} |
{error_info, #{ module => module(), function => atom(), cause => term() }} |
{atom(), term()}.
-doc """
An Erlang stacktrace as described by
[Errors and Error Handling](`e:system:errors.md#stacktrace`) section in the
Erlang Reference Manual.
""".
-type stacktrace() :: [{module(), atom(), arity() | [term()],
[stacktrace_extrainfo()]} |
{function(), arity() | [term()], [stacktrace_extrainfo()]}].
-doc "A binary data object, structured according to the Erlang external term format.".
-type ext_binary() :: binary().
-doc """
A term of type `t:iovec/0`, structured according to the Erlang external term
format.
""".
-type ext_iovec() :: iovec().
-doc "See [`erlang:timestamp/0`](`timestamp/0`).".
-type timestamp() :: {MegaSecs :: non_neg_integer(),
Secs :: non_neg_integer(),
MicroSecs :: non_neg_integer()}.
-doc """
The time unit used by erlang time APIs.
Supported time unit representations:
- **`PartsPerSecond :: integer() >= 1`** - Time unit expressed in parts per
second. That is, the time unit equals `1/PartsPerSecond` second.
- **`second`** - Symbolic representation of the time unit represented by the
integer `1`.
- **`millisecond`** - Symbolic representation of the time unit represented by
the integer `1000`.
- **`microsecond`** - Symbolic representation of the time unit represented by
the integer `1000_000`.
- **`nanosecond`** - Symbolic representation of the time unit represented by the
integer `1000_000_000`.
- **`native`** - Symbolic representation of the native time unit used by the
Erlang runtime system.
The `native` time unit is determined at runtime system start, and remains the
same until the runtime system terminates. If a runtime system is stopped and
then started again (even on the same machine), the `native` time unit of the
new runtime system instance can differ from the `native` time unit of the old
runtime system instance.
One can get an approximation of the `native` time unit by calling
[`erlang:convert_time_unit(1, second, native)`](`convert_time_unit/3`). The
result equals the number of whole `native` time units per second. If the
number of `native` time units per second does not add up to a whole number,
the result is rounded downwards.
> #### Note {: .info }
>
> The value of the `native` time unit gives you more or less no information
> about the quality of time values. It sets a limit for the
> [resolution](time_correction.md#time-resolution) and for the
> [precision](time_correction.md#time-precision) of time values, but it gives
> no information about the [accuracy](time_correction.md#time-accuracy) of
> time values. The resolution of the `native` time unit and the resolution of
> time values can differ significantly.
- **`perf_counter`** - Symbolic representation of the performance counter time
unit used by the Erlang runtime system.
The `perf_counter` time unit behaves much in the same way as the `native` time
unit. That is, it can differ between runtime restarts. To get values of this
type, call `os:perf_counter/0`.
- **`t:deprecated_time_unit/0`** -
Deprecated symbolic representations kept for backwards-compatibility.
The `t:time_unit/0` type can be extended. To convert time values between time
units, use [`erlang:convert_time_unit/3`](`convert_time_unit/3`).
""".
-type time_unit() ::
pos_integer()
| 'second'
| 'millisecond'
| 'microsecond'
| 'nanosecond'
| 'native'
| 'perf_counter'
| deprecated_time_unit().
%% Deprecated symbolic units...
-doc """
The `t:time_unit/0` type also consist of the following _deprecated_ symbolic
time units:
- **`seconds`** - Same as [`second`](`t:time_unit/0`).
- **`milli_seconds`** - Same as [`millisecond`](`t:time_unit/0`).
- **`micro_seconds`** - Same as [`microsecond`](`t:time_unit/0`).
- **`nano_seconds`** - Same as [`nanosecond`](`t:time_unit/0`).
""".
-type deprecated_time_unit() ::
'seconds'
| 'milli_seconds'
| 'micro_seconds'
| 'nano_seconds'.
-opaque prepared_code() :: reference().
-export_type([prepared_code/0]).
-doc """
An opaque handle identifying a
[NIF resource object ](erl_nif.md#resource_objects).
""".
-opaque nif_resource() :: reference().
-export_type([nif_resource/0]).
-doc "An opaque handle identifying a distribution channel.".
-opaque dist_handle() :: atom().
-export_type([dist_handle/0]).
-doc """
A list of binaries. This datatype is useful to use together with
[`enif_inspect_iovec`](erl_nif.md#enif_inspect_iovec).
""".
-type iovec() :: [binary()].
-export_type([iovec/0]).
%% Type for the destination of sends.
-export_type([send_destination/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Native code BIF stubs and their types
%% (BIF's actually implemented in this module goes last in the file)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Exports for all native code stubs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export([adler32/1, adler32/2, adler32_combine/3, append_element/2]).
-export([atom_to_binary/1, atom_to_binary/2]).
-export([atom_to_list/1, binary_part/2, binary_part/3]).
-export([binary_to_atom/1, binary_to_atom/2]).
-export([binary_to_existing_atom/1, binary_to_existing_atom/2]).
-export([binary_to_float/1]).
-export([binary_to_integer/1,binary_to_integer/2]).
-export([binary_to_list/1]).
-export([binary_to_list/3, binary_to_term/1, binary_to_term/2]).
-export([bit_size/1, bitstring_to_list/1]).
-export([bump_reductions/1, byte_size/1, call_on_load_function/1]).
-export([cancel_timer/1, cancel_timer/2, ceil/1,
check_old_code/1, check_process_code/2,
check_process_code/3, crc32/1]).
-export([crc32/2, crc32_combine/3, date/0, decode_packet/3]).
-export([delete_element/2]).
-export([delete_module/1, demonitor/1, demonitor/2, display/1]).
-export([display_string/1, display_string/2, erase/0, erase/1]).
-export([error/1, error/2, error/3, exit/1, exit/2, exit_signal/2, external_size/1]).
-export([external_size/2, finish_after_on_load/2, finish_loading/1, float/1]).
-export([float_to_binary/1, float_to_binary/2,
float_to_list/1, float_to_list/2, floor/1]).
-export([fun_info/2, fun_info_mfa/1, fun_to_list/1, function_exported/3]).
-export([garbage_collect/0, garbage_collect/1, garbage_collect/2]).
-export([garbage_collect_message_area/0, get/0, get/1, get_keys/0, get_keys/1]).
-export([get_module_info/1, group_leader/0]).
-export([group_leader/2]).
-export([halt/0, halt/1, halt/2,
has_prepared_code_on_load/1, hibernate/3]).
-export([insert_element/3]).
-export([integer_to_binary/1, integer_to_list/1]).
-export([iolist_size/1, iolist_to_binary/1, iolist_to_iovec/1]).
-export([is_alive/0, is_builtin/3, is_map_key/2, is_process_alive/1, length/1, link/1]).
-export([list_to_atom/1, list_to_binary/1]).
-export([list_to_bitstring/1, list_to_existing_atom/1, list_to_float/1]).
-export([list_to_integer/1, list_to_integer/2]).
-export([list_to_pid/1, list_to_port/1, list_to_ref/1, list_to_tuple/1, loaded/0]).
-export([localtime/0, make_ref/0]).
-export([map_size/1, map_get/2, match_spec_test/3, md5/1, md5_final/1]).
-export([md5_init/0, md5_update/2, module_loaded/1, monitor/2, monitor/3]).
-export([monitor_node/2, monitor_node/3, nif_error/1, nif_error/2]).
-export([node/0, node/1, now/0, phash/2, phash2/1, phash2/2]).
-export([pid_to_list/1, port_close/1, port_command/2, port_command/3]).
-export([port_connect/2, port_control/3, port_get_data/1]).
-export([port_set_data/2, port_to_list/1, ports/0]).
-export([posixtime_to_universaltime/1, pre_loaded/0, prepare_loading/2]).
-export([monotonic_time/0, monotonic_time/1]).
-export([system_time/0, system_time/1]).
-export([convert_time_unit/3]).
-export([unique_integer/0, unique_integer/1]).
-export([time_offset/0, time_offset/1, timestamp/0]).
-export([process_display/2]).
-export([process_flag/3, process_info/1, processes/0, purge_module/1]).
-export([put/2, raise/3, read_timer/1, read_timer/2, ref_to_list/1, register/2]).
-export([send_after/3, send_after/4, start_timer/3, start_timer/4]).
-export([registered/0, resume_process/1, round/1, self/0]).
-export([seq_trace/2, seq_trace_print/1, seq_trace_print/2, setnode/2]).
-export([setnode/3, size/1, spawn/3, spawn_link/3, split_binary/2]).
-export([suspend_process/2, system_monitor/0]).
-export([system_monitor/1, system_monitor/2, system_profile/0]).
-export([system_profile/2, throw/1, time/0, trace/3, trace_delivered/1]).
-export([trace_info/2]).
-export([trunc/1, tuple_size/1, universaltime/0]).
-export([universaltime_to_posixtime/1, unlink/1, unregister/1, whereis/1]).
-export([abs/1, append/2, element/2, get_module_info/2, hd/1,
is_atom/1, is_binary/1, is_bitstring/1, is_boolean/1,
is_float/1, is_function/1, is_function/2, is_integer/1,
is_list/1, is_map/1, is_number/1, is_pid/1, is_port/1, is_record/2,
is_record/3, is_reference/1, is_tuple/1, load_module/2,
load_nif/2, localtime_to_universaltime/2, make_fun/3,
make_tuple/2, make_tuple/3, open_port/2,
port_call/2, port_call/3, port_info/1, port_info/2, process_flag/2,
process_info/2, send/2, send/3, seq_trace_info/1,
setelement/3,
statistics/1, subtract/2, system_flag/2,
term_to_binary/1, term_to_binary/2,
term_to_iovec/1, term_to_iovec/2,
tl/1,
trace_pattern/2, trace_pattern/3,
tuple_to_list/1, system_info/1,
universaltime_to_localtime/1]).
-export([alias/0, alias/1, unalias/1]).
-export([dt_get_tag/0, dt_get_tag_data/0, dt_prepend_vm_tag_data/1, dt_append_vm_tag_data/1,
dt_put_tag/1, dt_restore_tag/1, dt_spread_tag/1]).
%% Operators
-export(['=='/2, '=:='/2,
'/='/2, '=/='/2,
'=<'/2, '>='/2,
'<'/2, '>'/2]).
-export(['-'/1, '+'/1,
'-'/2, '+'/2,
'/'/2, '*'/2,
'div'/2, 'rem'/2,
'bsl'/2, 'bsr'/2,
'bor'/2, 'band'/2,
'bxor'/2, 'bnot'/1]).
-export(['and'/2, 'or'/2,
'xor'/2, 'not'/1]).
-export(['--'/2, '++'/2]).
-export(['!'/2]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Simple native code BIFs
%%% These are here for the types/specs, the real implementation is in the C code.
%%% The first chunk is originally auto-generated from
%%% $ERL_TOP/lib/hipe/cerl/erl_bif_types.erl as released in R15B.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% types
-type fun_info_item() ::
arity |
env |
index |
name |
module |
new_index |
new_uniq |
pid |
type |
uniq.
-type seq_trace_info_returns() ::
{ 'send' | 'receive' | 'print' | 'timestamp' | 'monotonic_timestamp' | 'strict_monotonic_timestamp', boolean() } |
{ 'label', term() } |
{ 'serial', { non_neg_integer(), non_neg_integer() } } |
[].
-type system_profile_option() ::
'exclusive' |
'runnable_ports' |
'runnable_procs' |
'scheduler' |
'timestamp' |
'monotonic_timestamp' |
'strict_monotonic_timestamp'.
-type system_monitor_option() ::
'busy_port' |
'busy_dist_port' |
{'long_gc', non_neg_integer()} |
{'long_message_queue', {Disable :: non_neg_integer(),
Enable :: pos_integer()}} |
{'long_schedule', non_neg_integer()} |
{'large_heap', non_neg_integer()}.
-doc """
A extended `t:stacktrace/0` that can be passed to `raise/3`.
""".
-type raise_stacktrace() ::
[{module(), atom(), arity() | [term()]} |
{function(), arity() | [term()]}]
| stacktrace().
-export_type([raise_stacktrace/0]).
-type bitstring_list() ::
maybe_improper_list(byte() | bitstring() | bitstring_list(), bitstring() | []).
-type trace_flag() ::
all |
send |
'receive' |
procs |
ports |
call |
arity |
return_to |
silent |
running |
exiting |
running_procs |
running_ports |
garbage_collection |
timestamp |
cpu_timestamp |
monotonic_timestamp |
strict_monotonic_timestamp |
set_on_spawn |
set_on_first_spawn |
set_on_link |
set_on_first_link |
{tracer, pid() | port()} |
{tracer, module(), term()}.
-type trace_info_item_result() ::
{traced, global | local | false | undefined} |
{match_spec, trace_match_spec() | false | undefined} |
{meta, pid() | port() | false | undefined | []} |
{meta, module(), term() } |
{meta_match_spec, trace_match_spec() | false | undefined} |
{call_count, non_neg_integer() | boolean() | undefined} |
{call_time | call_memory, [{pid(), non_neg_integer(),
non_neg_integer(), non_neg_integer()}] | boolean() | undefined}.
-type trace_info_flag() ::
send |
'receive' |
set_on_spawn |
call |
return_to |
procs |
set_on_first_spawn |
set_on_link |
running |
garbage_collection |
timestamp |
monotonic_timestamp |
strict_monotonic_timestamp |
arity.
-type trace_info_return() ::
undefined |
{flags, [trace_info_flag()]} |
{tracer, pid() | port() | []} |
{tracer, module(), term()} |
trace_info_item_result() |
{all, [ trace_info_item_result() ] | false | undefined}.
%% Specs and stubs
%% adler32/1
-doc "Computes and returns the adler32 checksum for `Data`.".
-doc #{ group => checksum }.
-spec adler32(Data) -> non_neg_integer() when
Data :: iodata().
adler32(_Data) ->
erlang:nif_error(undefined).
%% adler32/2
-doc """
Continues computing the adler32 checksum by combining the previous checksum,
`OldAdler`, with the checksum of `Data`.
The following code:
```erlang
X = erlang:adler32(Data1),
Y = erlang:adler32(X,Data2).
```
assigns the same value to `Y` as this:
```erlang
Y = erlang:adler32([Data1,Data2]).
```
""".
-doc #{ group => checksum }.
-spec adler32(OldAdler, Data) -> non_neg_integer() when
OldAdler :: non_neg_integer(),
Data :: iodata().
adler32(_OldAdler, _Data) ->
erlang:nif_error(undefined).
%% adler32_combine/3
-doc """
Combines two previously computed adler32 checksums.
This computation requires the size of the data object for the second checksum
to be known.
The following code:
```erlang
Y = erlang:adler32(Data1),
Z = erlang:adler32(Y,Data2).
```
assigns the same value to `Z` as this:
```erlang
X = erlang:adler32(Data1),
Y = erlang:adler32(Data2),
Z = erlang:adler32_combine(X,Y,iolist_size(Data2)).
```
""".
-doc #{ group => checksum }.
-spec adler32_combine(FirstAdler, SecondAdler, SecondSize) -> non_neg_integer() when
FirstAdler :: non_neg_integer(),
SecondAdler :: non_neg_integer(),
SecondSize :: non_neg_integer().
adler32_combine(_FirstAdler, _SecondAdler, _SecondSize) ->
erlang:nif_error(undefined).
%% append_element/2
-doc """
Returns a new tuple that has one element more than `Tuple1`, and contains the
elements in `Tuple1` followed by `Term` as the last element.
Semantically equivalent to
[`list_to_tuple(tuple_to_list(Tuple1) ++ [Term])`](`list_to_tuple/1`), but much
faster.
For example:
```erlang
> erlang:append_element({one, two}, three).
{one,two,three}
```
""".
-doc #{ group => terms }.
-spec append_element(Tuple1, Term) -> Tuple2 when
Tuple1 :: tuple(),
Tuple2 :: tuple(),
Term :: term().
append_element(_Tuple1, _Term) ->
erlang:nif_error(undefined).
%% atom_to_binary/1
-doc(#{ equiv => atom_to_binary(Atom, utf8) }).
-doc(#{since => <<"OTP 23.0">>}).
-doc #{ group => terms }.
-spec atom_to_binary(Atom) -> binary() when
Atom :: atom().
atom_to_binary(Atom) ->
try
erlang:atom_to_binary(Atom, utf8)
catch
error:Error ->
error_with_info(Error, [Atom])
end.
%% atom_to_binary/2
-doc """
Returns a binary corresponding to the text representation of `Atom`.
If `Encoding` is `latin1`, one byte exists for each character in the text
representation. If `Encoding` is `utf8` or `unicode`, the characters are encoded
using UTF-8 where characters may require multiple bytes.
> #### Change {: .info }
>
> As from Erlang/OTP 20, atoms can contain any Unicode character and
> [`atom_to_binary(Atom, latin1)`](`atom_to_binary/2`) may fail if the text
> representation for `Atom` contains a Unicode character > 255.
Example:
```erlang
> atom_to_binary('Erlang', latin1).
<<"Erlang">>
```
""".
-doc #{ group => terms }.
-spec atom_to_binary(Atom, Encoding) -> binary() when
Atom :: atom(),
Encoding :: latin1 | unicode | utf8.
atom_to_binary(_Atom, _Encoding) ->
erlang:nif_error(undefined).
%% atom_to_list/1
-doc """
Returns a list of unicode code points corresponding to the text representation
of `Atom`.
For example:
```erlang
> atom_to_list('Erlang').
"Erlang"
```
```erlang
> atom_to_list('你好').
[20320,22909]
```
See `m:unicode` for how to convert the resulting list to different formats.
""".
-doc #{ group => terms }.
-spec atom_to_list(Atom) -> string() when
Atom :: atom().
atom_to_list(_Atom) ->
erlang:nif_error(undefined).
%% binary_part/2
%% Shadowed by erl_bif_types: erlang:binary_part/2
-doc """
Extracts the part of the binary described by `PosLen`.
Negative length can be used to extract bytes at the end of a binary.
For example:
```erlang
1> Bin = <<1,2,3,4,5,6,7,8,9,10>>.
2> binary_part(Bin,{byte_size(Bin), -5}).
<<6,7,8,9,10>>
```
Failure: `badarg` if `PosLen` in any way references outside the binary.
`Start` is zero-based, that is:
```erlang
1> Bin = <<1,2,3>>
2> binary_part(Bin,{0,2}).
<<1,2>>
```
For details about the `PosLen` semantics, see `m:binary`.
""".
-doc #{ group => terms }.
-doc(#{since => <<"OTP R14B">>}).
-spec binary_part(Subject, PosLen) -> binary() when
Subject :: binary(),
PosLen :: {Start :: non_neg_integer(), Length :: integer()}.
binary_part(_Subject, _PosLen) ->
erlang:nif_error(undefined).
%% binary_part/3
%% Shadowed by erl_bif_types: erlang:binary_part/3
-doc( #{ equiv => binary_part(Subject, {Start, Length}) }).
-doc(#{since => <<"OTP R14B">>}).
-doc #{ group => terms }.
-spec binary_part(Subject, Start, Length) -> binary() when
Subject :: binary(),
Start :: non_neg_integer(),
Length :: integer().
binary_part(_Subject, _Start, _Length) ->
erlang:nif_error(undefined).
%% binary_to_atom/1
-doc(#{ equiv => binary_to_atom(Binary, utf8) }).
-doc(#{since => <<"OTP 23.0">>}).
-doc #{ group => terms }.
-spec binary_to_atom(Binary) -> atom() when
Binary :: binary().
binary_to_atom(Binary) ->
try
erlang:binary_to_atom(Binary, utf8)
catch
error:Error -> error_with_info(Error, [Binary])
end.
%% binary_to_atom/2
-doc """
Returns the atom whose text representation is `Binary`. If `Encoding` is `utf8`
or `unicode`, the binary must contain valid UTF-8 sequences.
> #### Change {: .info }
>
> As from Erlang/OTP 20, [`binary_to_atom(Binary, utf8)`](`binary_to_atom/2`) is
> capable of decoding any Unicode character. Earlier versions would fail if the
> binary contained Unicode characters > 255.
> #### Note {: .info }
>
> The number of characters that are permitted in an atom name is limited. The
> default limits can be found in the
> [Efficiency Guide (section System Limits)](`e:system:system_limits.md`).
> #### Note {: .info }
>
> There is configurable limit on how many atoms that can exist and atoms are not
> garbage collected. Therefore, it is recommended to consider whether
> [`binary_to_existing_atom/2`](`binary_to_existing_atom/2`) is a better option
> than [`binary_to_atom/2`](`binary_to_atom/2`). The default limits can be found
> in [Efficiency Guide (section System Limits)](`e:system:system_limits.md#atoms`).
Examples:
```erlang
> binary_to_atom(<<"Erlang">>, latin1).
'Erlang'
```
```erlang
> binary_to_atom(<<1024/utf8>>, utf8).
'Ѐ'
```
""".
-doc #{ group => terms }.
-spec binary_to_atom(Binary, Encoding) -> atom() when
Binary :: binary(),
Encoding :: latin1 | unicode | utf8.
binary_to_atom(_Binary, _Encoding) ->
erlang:nif_error(undefined).
%% binary_to_existing_atom/1
-doc(#{ equiv => binary_to_existing_atom(Binary, utf8) }).
-doc(#{since => <<"OTP 23.0">>}).
-doc #{ group => terms }.
-spec binary_to_existing_atom(Binary) -> atom() when
Binary :: binary().
binary_to_existing_atom(Binary) ->
try
erlang:binary_to_existing_atom(Binary, utf8)
catch
error:Error -> error_with_info(Error, [Binary])
end.
%% binary_to_existing_atom/2
-doc """
As `binary_to_atom/2`, but the atom must exist.
The Erlang system has a [configurable limit](`e:system:system_limits.md#atoms`) for the
total number of atoms that can exist, and atoms are not garbage collected.
Therefore, it is not safe to create many atoms from binaries that come from an
untrusted source (for example, a file fetched from the Internet), for example,
using `binary_to_atom/2`. This function is thus the appropriate option when the
input binary comes from an untrusted source.
An atom exists in an Erlang system when included in a loaded Erlang module or
when created programmatically (for example, by
[`binary_to_atom/2`](`binary_to_atom/2`)). See the next note for an example of
when an atom exists in the source code for an Erlang module but not in the
compiled version of the same module.
Failure: `badarg` if the atom does not exist.
> #### Note {: .info }
>
> Note that the compiler may optimize away atoms. For example, the compiler will
> rewrite [`atom_to_list(some_atom)`](`atom_to_list/1`) to `"some_atom"`. If
> that expression is the only mention of the atom `some_atom` in the containing
> module, the atom will not be created when the module is loaded, and a
> subsequent call to
> [`binary_to_existing_atom(<<"some_atom">>, utf8)`](`binary_to_existing_atom/2`)
> will fail.
> #### Note {: .info }
>
> The number of characters that are permitted in an atom name is limited. The
> default limits can be found in the
> [Efficiency Guide (section System Limits)](`e:system:system_limits.md`).
""".
-doc #{ group => terms }.
-spec binary_to_existing_atom(Binary, Encoding) -> atom() when
Binary :: binary(),
Encoding :: latin1 | unicode | utf8.
binary_to_existing_atom(_Binary, _Encoding) ->
erlang:nif_error(undefined).
%% binary_to_float/1
-doc """
Returns the float whose text representation is `Binary`.
For example:
```erlang
> binary_to_float(<<"2.2017764e+0">>).
2.2017764
```
The float string format is the same as the format for
[Erlang float literals](`e:system:data_types.md`) except for that underscores
are not permitted.
Failure: `badarg` if `Binary` contains a bad representation of a float.
""".
-doc(#{since => <<"OTP R16B">>}).
-doc #{ group => terms }.
-spec binary_to_float(Binary) -> float() when
Binary :: binary().
binary_to_float(_Binary) ->
erlang:nif_error(undefined).
%% binary_to_integer/1
-doc """
Returns an integer whose text representation is `Binary`.
For example:
```erlang
> binary_to_integer(<<"123">>).
123
```
[`binary_to_integer/1`](`binary_to_integer/1`) accepts the same string formats
as `list_to_integer/1`.
Failure: `badarg` if `Binary` contains a bad representation of an integer.
""".
-doc(#{since => <<"OTP R16B">>}).
-doc #{ group => terms }.
-spec binary_to_integer(Binary) -> integer() when
Binary :: binary().
binary_to_integer(Binary) ->
case erts_internal:binary_to_integer(Binary, 10) of