summaryrefslogtreecommitdiff
path: root/lib/compiler/doc/src/compile.xml
blob: b2d9a143abe0dbd5d62af571fe5f07fc12810d07 (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE erlref SYSTEM "erlref.dtd">

<erlref>
  <header>
    <copyright>
      <year>1996</year><year>2021</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      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.

    </legalnotice>

    <title>compile</title>
    <prepared>Robert Virding</prepared>
    <docno></docno>
    <date>1996-11-04</date>
    <rev>A</rev>
    <file>compile.sgml</file>
  </header>
  <module since="">compile</module>
  <modulesummary>Erlang Compiler</modulesummary>
  <description>
    <p>This module provides an interface to the standard Erlang
      compiler. It can generate either a new file, which contains
      the object code, or return a binary, which can be loaded directly.
    </p>
  </description>

  <datatypes>
    <datatype>
      <name>option() = term()</name>
      <desc><p>See <seemfa marker="#file/2">file/2</seemfa> for detailed description</p></desc>
    </datatype>
    <datatype>
      <name>forms() = term()</name>
      <desc><p>List of Erlang abstract or Core Erlang format representations, as used by <seemfa marker="#forms/2">forms/2</seemfa></p></desc>
    </datatype>
  </datatypes>

  <funcs>
    <func>
      <name since="OTP 19.0">env_compiler_options()</name>
      <fsummary>
	Compiler options defined via the environment variable
	<c>ERL_COMPILER_OPTIONS</c>
      </fsummary>
      <desc>
	<p>Return compiler options given via the environment variable
	  <c>ERL_COMPILER_OPTIONS</c>. If the value is a list, it is
	  returned as is. If it is not a list, it is put into a list.
	</p>
      </desc>
    </func>
    <func>
      <name since="">file(File)</name>
      <fsummary>Compiles a file.</fsummary>
      <desc>
        <p>Is the same as
	  <c>file(File, [verbose,report_errors,report_warnings])</c>.
	</p>
      </desc>
    </func>

    <func>
      <name since="">file(File, Options) -> CompRet</name>
      <fsummary>Compiles a file.</fsummary>
      <type>
        <v>CompRet = ModRet | BinRet | ErrRet</v>
        <v>ModRet = {ok,ModuleName} | {ok,ModuleName,Warnings}</v>
        <v>BinRet = {ok,ModuleName,Binary} | {ok,ModuleName,Binary,Warnings}</v>
        <v>ErrRet = error | {error,Errors,Warnings}</v>
      </type>
      <desc>
        <p>Compiles the code in the file <c>File</c>, which is an
	  Erlang source code file without the <c>.erl</c> extension.
	  <c>Options</c> determine the behavior of the compiler.</p>

        <p>Returns <c>{ok,ModuleName}</c> if successful, or <c>error</c>
	  if there are errors. An object code file is created if
	  the compilation succeeds without errors. It is considered
	  to be an error if the module name in the source code is
	  not the same as the basename of the output file.</p>

        <p>Available options:</p>
        <taglist>
	  <tag><c>brief</c></tag>
          <item>
            <p>Restricts error and warning messages to a single line of output.
            As of OTP 24, the compiler will by default also display the part
            of the source code that the message refers to.</p>
          </item>

          <tag><c>basic_validation</c></tag>
          <item>
            <p>This option is a fast way to test whether a module will
	      compile successfully. This is useful for code generators
              that want to verify the code that they emit. No code is
	      generated. If warnings are enabled, warnings generated by
	      the <c>erl_lint</c> module (such as warnings for unused
	      variables and functions) are also returned.</p>

            <p>Use option <c>strong_validation</c> to generate all
	      warnings that the compiler would generate.</p>
          </item>

          <tag><c>strong_validation</c></tag>
          <item>
            <p>Similar to option <c>basic_validation</c>. No code
	      is generated, but more compiler passes are run
	      to ensure that warnings generated by the optimization
	      passes are generated (such as clauses that will not match,
	      or expressions that are guaranteed to fail with an
	      exception at runtime).</p>
          </item>

          <tag><c>binary</c></tag>
          <item>
            <p>The compiler returns the object code in a
              binary instead of creating an object file. If successful,
              the compiler returns <c>{ok,ModuleName,Binary}</c>.</p>
          </item>

          <tag><c>bin_opt_info</c></tag>
          <item>
            <p>The compiler will emit informational warnings about binary
	    matching optimizations (both successful and unsuccessful).
	    For more information, see the section about
	    <seeguide marker="system/efficiency_guide:binaryhandling#bin_opt_info">bin_opt_info</seeguide>
	    in the Efficiency Guide.</p>
          </item>

          <tag><c>{compile_info, [{atom(), term()}]}</c></tag>
          <item>
            <p>Allows compilers built on top of <c>compile</c> to attach
            extra compilation metadata to the <c>compile_info</c> chunk
            in the generated beam file.</p>

            <p>It is advised for compilers to remove all non-deterministic
            information if the <c>deterministic</c> option is supported and
            it was supplied by the user.</p>
          </item>

          <tag><c>compressed</c></tag>
          <item>
            <p>The compiler will compress the generated object code,
	    which can be useful for embedded systems.</p>
          </item>

          <tag><c>debug_info</c></tag>
          <item>
            <marker id="debug_info"></marker>
            <p>Includes debug information in the form of <seeguide marker="erts:absform">
              Erlang Abstract Format</seeguide> in the <c>debug_info</c>
              chunk of the compiled beam module. Tools such as Debugger,
              Xref, and Cover require the debug information to be included.</p>

            <p><em>Warning</em>: Source code can be reconstructed from
              the debug information. Use encrypted debug information
              (<c>encrypt_debug_info</c>) to prevent this.</p>

            <p>For details, see
              <seeerl marker="stdlib:beam_lib#debug_info">beam_lib(3)</seeerl>.</p>
          </item>

          <tag><c>{debug_info, {Backend, Data}}</c></tag>
          <item>
            <marker id="debug_info"></marker>
            <p>Includes custom debug information in the form of a
              <c>Backend</c> module with custom <c>Data</c> in the compiled beam module.
              The given module must implement a <c>debug_info/4</c> function
              and is responsible for generating different code representations,
              as described in the <c>debug_info</c> under
              <seeerl marker="stdlib:beam_lib#debug_info">beam_lib(3)</seeerl>.</p>

            <p><em>Warning</em>: Source code can be reconstructed from
              the debug information. Use encrypted debug information
              (<c>encrypt_debug_info</c>) to prevent this.</p>
          </item>

          <tag><c>{debug_info_key,KeyString}</c></tag>
          <item></item>
          <tag><c>{debug_info_key,{Mode,KeyString}}</c></tag>
          <item>
            <marker id="debug_info_key"></marker>
            <p>Includes debug information, but encrypts it so that it
              cannot be accessed without supplying the key. (To give
              option <c>debug_info</c> as well is allowed, but
              not necessary.) Using this option is a good way to always
              have the debug information available during testing, yet
              protecting the source code.</p>
            <p><c>Mode</c> is the type of crypto algorithm to be used
              for encrypting the debug information. The default
              (and currently the only) type is <c>des3_cbc</c>.</p>
            <p>For details, see
              <seeerl marker="stdlib:beam_lib#debug_info">beam_lib(3)</seeerl>.</p>
          </item>

          <tag><c>encrypt_debug_info</c></tag>
          <item>
            <marker id="encrypt_debug_info"></marker>
            <p>Similar to the <c>debug_info_key</c> option, but
	      the key is read from an <c>.erlang.crypt</c> file.
	    </p>

	    <p>For details, see
              <seeerl marker="stdlib:beam_lib#debug_info">beam_lib(3)</seeerl>.</p>
          </item>

          <tag><c>deterministic</c></tag>
          <item>
            <p>Omit the <c>options</c> and <c>source</c> tuples in
            the list returned by <c>Module:module_info(compile)</c>, and
            reduce the paths in stack traces to the module name alone.
	    This option will make it easier to achieve reproducible builds.
	    </p>
          </item>

          <tag><c>makedep</c></tag>
          <item>
            <p>Produces a Makefile rule to track headers dependencies.
              No object file is produced.
            </p>
            <p>By default, this rule is written to
              <c><![CDATA[<File>.Pbeam]]></c>. However, if option
                <c>binary</c> is set, nothing is written and the rule is
                returned in <c>Binary</c>.
            </p>
            <p>The output will be encoded in UTF-8.</p>
            <p>For example, if you have the following module:
            </p>
            <code>
-module(module).

-include_lib("eunit/include/eunit.hrl").
-include("header.hrl").</code>
            <p>The Makefile rule generated by this option looks as follows:
            </p>
            <code>
module.beam: module.erl \
  /usr/local/lib/erlang/lib/eunit/include/eunit.hrl \
  header.hrl</code>
          </item>

          <tag><c>makedep_side_effect</c></tag>
          <item>
	    <p>The dependecies are created as a side effect to the
	    normal compilation process. This means that the object
	    file will also be produced. This option override the
	    <c>makedep</c> option.
	    </p>
	  </item>

          <tag><c>{makedep_output, Output}</c></tag>
          <item>
            <p>Writes generated rules to <c>Output</c> instead of the
              default <c><![CDATA[<File>.Pbeam]]></c>. <c>Output</c>
              can be a filename or an <c>io_device()</c>. To write to
              stdout, use <c>standard_io</c>. However, if <c>binary</c>
              is set, nothing is written to <c>Output</c> and the
              result is returned to the caller with
              <c>{ok, ModuleName, Binary}</c>.
            </p>
          </item>

          <tag><c>{makedep_target, Target}</c></tag>
          <item>
            <p>Changes the name of the rule emitted to <c>Target</c>.
            </p>
          </item>

          <tag><c>makedep_quote_target</c></tag>
          <item>
            <p>Characters in <c>Target</c> special to make(1) are quoted.
            </p>
          </item>

          <tag><c>makedep_add_missing</c></tag>
          <item>
            <p>Considers missing headers as generated files and adds them to the
              dependencies.
            </p>
          </item>

          <tag><c>makedep_phony</c></tag>
          <item>
            <p>Adds a phony target for each dependency.
            </p>
          </item>

          <tag><c>'P'</c></tag>
          <item>
            <p>Produces a listing of the parsed code, after preprocessing
	      and parse transforms, in the file
	      <c><![CDATA[<File>.P]]></c>. No object file is produced.
	    </p>
          </item>

          <tag><c>'E'</c></tag>
          <item>
            <p>Produces a listing of the code, after all source code
	      transformations have been performed, in the file
	      <c><![CDATA[<File>.E]]></c>. No object file is produced.
	    </p>
          </item>

          <tag><c>'S'</c></tag>
          <item>
            <p>Produces a listing of the assembler code in the file
              <c><![CDATA[<File>.S]]></c>. No object file is produced.
	    </p>
          </item>

          <tag><c>recv_opt_info</c></tag>
          <item>
            <p>The compiler will emit informational warnings about selective
              receive optimizations (both successful and unsuccessful). For
              more information, see the section about
              <seeguide marker="system/efficiency_guide:processes#receiving-messages">
              selective receive optimization</seeguide> in the Efficiency
              Guide.</p>
          </item>

          <tag><c>report_errors/report_warnings</c></tag>
          <item>
            <p>Causes errors/warnings to be printed as they occur.</p>
          </item>

          <tag><c>report</c></tag>
          <item>
            <p>A short form for both <c>report_errors</c> and
              <c>report_warnings</c>.</p>
          </item>

          <tag><c>return_errors</c></tag>
          <item>
            <p>If this flag is set,
	      <c>{error,ErrorList,WarningList}</c> is returned when
	      there are errors.</p>
          </item>

          <tag><c>return_warnings</c></tag>
          <item>
            <p>If this flag is set, an extra field, containing
              <c>WarningList</c>, is added to the tuples returned on
              success.</p>
          </item>

          <tag><c>warnings_as_errors</c></tag>
          <item>
            <p>Causes warnings to be treated as errors. This option is supported
            since R13B04.</p>
          </item>

	  <tag><c>{error_location,line | column}</c></tag>
	  <item>
            <p>If the value of this flag is <c>line</c>, the location
            <seeerl marker="#error_information"><c>ErrorLocation</c></seeerl>
            of warnings and errors is a line number. If
            the value is <c>column</c>, <c>ErrorLocation</c> includes
            both a line number and a column number.
	    Default is <c>column</c>. This option is supported
            since Erlang/OTP 24.0.</p>
            <p>If the value of this flag is <c>column</c>,
            <seeerl marker="#debug_info">debug information</seeerl>
	    includes column information.</p>
	  </item>

          <tag><c>return</c></tag>
          <item>
            <p>A short form for both <c>return_errors</c> and
              <c>return_warnings</c>.</p>
          </item>

	  <tag><c>verbose</c></tag>
          <item>
            <p>Causes more verbose information from the compiler,
              describing what it is doing.</p>
          </item>

	  <tag><c>{source,FileName}</c></tag>
          <item>
            <p>Overrides the source file name as presented in
              <c>module_info(compile)</c> and stack traces.</p>
          </item>

	  <tag><c>{outdir,Dir}</c></tag>
          <item>
            <p>Sets a new directory for the object code. The current
              directory is used for output, except when a directory
              has been specified with this option.</p>
          </item>

	  <tag><c>export_all</c></tag>
          <item>
            <p>Causes all functions in the module to be exported.</p>
          </item>

	  <tag><c>{i,Dir}</c></tag>
          <item>
            <p>Adds <c>Dir</c> to the list of directories to be searched
              when including a file. When encountering an
	      <c>-include</c> or <c>-include_lib</c> directive,
	      the compiler searches for header files in the following
	      directories:</p>
            <list type="ordered">
              <item>
                <p><c>"."</c>, the current working directory of
		  the file server</p>
              </item>
              <item>
                <p>The base name of the compiled file</p>
              </item>
              <item>
                <p>The directories specified using option <c>i</c>;
                  the directory specified last is searched first</p>
              </item>
            </list>
          </item>

          <tag><c>{d,Macro}</c></tag>
          <item></item>
          <tag><c>{d,Macro,Value}</c></tag>
          <item>
            <p>Defines a macro <c>Macro</c> to have the value
            <c>Value</c>. <c>Macro</c> is of type atom, and <c>Value</c> can be any term.
            The default <c>Value</c> is <c>true</c>.</p>
          </item>

	  <tag><c>{parse_transform,Module}</c></tag>
          <item>
            <p>Causes the parse transformation function
              <c>Module:parse_transform/2</c> to be applied to the
              parsed code before the code is checked for errors.</p>
          </item>

	  <tag><c>from_abstr</c></tag>
          <item>
            <p>The input file is expected to contain Erlang terms representing
            forms in abstract format (default file suffix ".abstr"). Note
            that the format of such terms can change between releases.</p>
            <p>See also the <c>no_lint</c> option.</p>
          </item>

	  <tag><c>from_asm</c></tag>
          <item>
            <p>The input file is expected to be assembler code (default
	      file suffix ".S"). Notice that the format of assembler files
              is not documented, and can change between releases.</p>
          </item>

	  <tag><c>from_core</c></tag>
          <item>
            <p>The input file is expected to be core code (default
	      file suffix ".core"). Notice that the format of core files
              is not documented, and can change between releases.</p>
          </item>

          <tag><c>no_spawn_compiler_process</c></tag>
          <item>
            <p>By default, all code is compiled in a separate process
              which is terminated at the end of compilation. However,
              some tools, like Dialyzer or compilers for other BEAM languages,
              may already manage their own worker processes and spawning
              an extra process may slow the compilation down.
              In such scenarios, you can pass this option to stop the
              compiler from spawning an additional process.</p>
          </item>

          <tag><c>no_strict_record_tests</c></tag>
          <item>
            <p>This option is not recommended.</p>

	    <p>By default, the generated code for
	      operation <c>Record#record_tag.field</c> verifies that
	      the tuple <c>Record</c> has the correct size for
	      the record, and that the first element is the tag
	      <c>record_tag</c>. Use this option to omit
	      the verification code.</p>
          </item>

          <tag><c>no_error_module_mismatch</c></tag>
          <item>
            <p>Normally the compiler verifies that the module name
	    given in the source code is the same as the base name
	    of the output file and refuses to generate an output file
	    if there is a mismatch. If you have a good reason (or
	    other reason) for having a module name unrelated to the
	    name of the output file, this option disables that verification
	    (there will not even be a warning if there is a mismatch).</p>
          </item>

          <tag><c>{no_auto_import,[{F,A}, ...]}</c></tag>
          <item>
	  <p>Makes the function <c>F/A</c> no longer being
          auto-imported from the <c>erlang</c> module, which resolves
          BIF name clashes. This option must be used to resolve name
          clashes with BIFs auto-imported before R14A, if it is needed to
          call the local function with the same name as an
          auto-imported BIF without module prefix.</p>
	  <note>
	  <p>As from R14A and forward, the compiler resolves calls
	  without module prefix to local or imported functions before
	  trying with auto-imported BIFs. If the BIF is to be
	  called, use the <c>erlang</c> module prefix in the call, not
	  <c>{no_auto_import,[{F,A}, ...]}</c>.</p>
	  </note>
	  <p>If this option is written in the source code, as a 
	  <c>-compile</c> directive, the syntax <c>F/A</c> can be used instead 
	  of <c>{F,A}</c>, for example:</p>
	  <code>-compile({no_auto_import,[error/1]}).</code>
	  </item>

          <tag><c>no_auto_import</c></tag>
          <item>
            <p>Do not auto-import any functions from <c>erlang</c> module.</p>
          </item>

          <tag><c>no_line_info</c></tag>
          <item>
            <p>Omits line number information to produce a slightly
	      smaller output file.
	    </p>
          </item>

          <tag><c>no_lint</c></tag>
          <item>
            <p>Skips the pass that checks for errors and warnings. Only
            applicable together with the <c>from_abstr</c> option. This is
            mainly for implementations of other languages on top of Erlang,
            which have already done their own checks to guarantee
            correctness of the code.</p>
            <p>Caveat: When this option is used, there are no guarantees
            that the code output by the compiler is correct and safe to
            use. The responsibility for correctness lies on the code or
            person generating the abstract format. If the code contains
            errors, the compiler may crash or produce unsafe code.</p>
          </item>

          <tag><c>{extra_chunks, [{binary(), binary()}]}</c></tag>
          <item>
            <p>Pass extra chunks to be stored in the <c>.beam</c> file.
              The extra chunks must be a list of tuples with a four byte
              binary as chunk name followed by a binary with the chunk contents.
              See <seeerl marker="stdlib:beam_lib">beam_lib</seeerl> for
              more information.
	    </p>
          </item>
        </taglist>

        <p>If warnings are turned on (option <c>report_warnings</c>
          described earlier), the following options control what type of
          warnings that are generated.
	  <marker id="erl_lint_options"></marker>
          Except from <c>{warn_format,Verbosity}</c>, the following options 
	have two forms:</p>
	  <list type="bulleted">
	    <item>A <c>warn_xxx</c> form, to turn on the warning.</item>
	    <item>A <c>nowarn_xxx</c> form, to turn off the warning.</item>
	  </list>
	  <p>In the descriptions that follow, the form that is used to change 
	  the default value are listed.</p>

        <taglist>
          <tag><c>{warn_format, Verbosity}</c></tag>
          <item>
            <p>Causes warnings to be emitted for malformed format
              strings as arguments to <c>io:format</c> and similar
              functions.</p>
	      <p><c>Verbosity</c> selects the number of warnings:</p>
	      <list type="bulleted">
		<item><c>0</c> = No warnings</item>
		<item><c>1</c> = Warnings for invalid format strings and incorrect 
		number of arguments</item>
		<item><c>2</c> = Warnings also when the validity cannot 
		be checked, for example, when the format string argument is a
		variable.</item>
	      </list>
	      <p>The default verbosity is <c>1</c>. Verbosity <c>0</c> can
              also be selected by option <c>nowarn_format</c>.</p>
          </item>

          <tag><c>nowarn_bif_clash</c></tag>
          <item>
            <p>This option is removed, it generates a fatal error if used.</p>

	    <warning>
	    <p>As from beginning with R14A, the compiler no longer calls the
	    auto-imported BIF if the name clashes with a local or
	    explicitly imported function, and a call without explicit
	    module name is issued. Instead, the local or imported
	    function is called. Still accepting <c>nowarn_bif_clash</c> would 
	    make a module calling functions clashing with auto-imported BIFs
	    compile with both the old and new compilers, but with
	    completely different semantics. This is why the option is removed.</p>

	    <p>The use of this option has always been discouraged.
	    As from R14A, it is an error to use it.</p>
	    <p>To resolve BIF clashes, use explicit module names or the
	    <c>{no_auto_import,[F/A]}</c> compiler directive.</p>
	    </warning>
          </item>

          <tag><c>{nowarn_bif_clash, FAs}</c></tag>
          <item>
            <p>This option is removed, it generates a fatal error if used.</p>

	    <warning>
	    <p>The use of this option has always been discouraged.
	    As from R14A, it is an error to use it.</p>
	    <p>To resolve BIF clashes, use explicit module names or the
	    <c>{no_auto_import,[F/A]}</c> compiler directive.</p>
	    </warning>
          </item>

	  <tag><c>nowarn_export_all</c></tag>
          <item>
	      <p>Turns off warnings for uses of the <c>export_all</c>
	      option. Default is to emit a warning if option
	      <c>export_all</c> is also given.</p>
          </item>

	  <tag><c>warn_export_vars</c></tag>
          <item>
	    <p>Emits warnings for all implicitly exported variables 
	      referred to after the primitives where they were first defined. 
	      By default, the compiler only emits warnings for exported 
	      variables referred to in a pattern.</p>
          </item>

	  <tag><c>nowarn_shadow_vars</c></tag>
          <item>
	      <p>Turns off warnings for "fresh" variables 
	      in functional objects or list comprehensions with the same 
	      name as some already defined variable. Default is to 
	      emit warnings for such variables.</p>   
          </item>

	  <tag><c>nowarn_unused_function</c></tag>
          <item>
            <p>Turns off warnings for unused local functions. Default 
	    is to emit warnings for all local functions that are not called
	      directly or indirectly by an exported function.
              The compiler does not include unused local functions in
	      the generated beam file, but the warning is still useful
	      to keep the source code cleaner.</p>
          </item>

	  <tag><c>{nowarn_unused_function, FAs}</c></tag>
          <item>
            <p>Turns off warnings for unused local functions like
              <c>nowarn_unused_function</c> does, but only for the mentioned
              local functions. <c>FAs</c> is a tuple <c>{Name,Arity}</c>
              or a list of such tuples.</p>
          </item>

	  <tag><c>nowarn_deprecated_function</c></tag>
          <item>
            <p>Turns off warnings for calls to deprecated functions. Default 
	    is to emit warnings for every call to a function known by the 
	    compiler to be deprecated. Notice that the compiler does not know
	      about attribute <c>-deprecated()</c>, but uses an
	      assembled list of deprecated functions in Erlang/OTP. To
	      do a more general check, the Xref tool can be used.
	      See also
	      <seeerl marker="tools:xref#deprecated_function">xref(3)</seeerl>
              and the function
	      <seemfa marker="tools:xref#m/1">xref:m/1</seemfa>, also
              accessible through the function 
	    <seemfa marker="stdlib:c#xm/1">c:xm/1</seemfa>.</p>
          </item>

	  <tag><c>{nowarn_deprecated_function, MFAs}</c></tag>
          <item>
            <p>Turns off warnings for calls to deprecated functions like
	      <c>nowarn_deprecated_function</c> does, but only for
	      the mentioned functions. <c>MFAs</c> is a tuple
              <c>{Module,Name,Arity}</c> or a list of such tuples.</p>
          </item>

	  <tag><c>nowarn_deprecated_type</c></tag>
          <item>
            <p>Turns off warnings for use of deprecated types. Default 
	    is to emit warnings for every use of a type known by the compiler
	    to be deprecated.</p>
          </item>

	  <tag><c>nowarn_removed</c></tag>
          <item>
            <p>Turns off warnings for calls to functions that have
            been removed. Default is to emit warnings for every call
            to a function known by the compiler to have been recently
            removed from Erlang/OTP.</p>
          </item>

	  <tag><c>{nowarn_removed, ModulesOrMFAs}</c></tag>
          <item>
            <p>Turns off warnings for calls to modules or functions
            that have been removed. Default is to emit warnings for
            every call to a function known by the compiler to have
            been recently removed from Erlang/OTP.</p>
          </item>

	  <tag><c>nowarn_obsolete_guard</c></tag>
          <item>
            <p>Turns off warnings for calls to old type testing BIFs, 
	    such as <c>pid/1</c> and <c>list/1</c>. See the
	    <seeguide marker="system/reference_manual:expressions#guards">Erlang Reference Manual</seeguide>
	      for a complete list of type testing BIFs and their old
	      equivalents. Default is to emit warnings for calls to
	      old type testing BIFs.</p>
          </item>

	  <tag><c>warn_unused_import</c></tag>
          <item>
            <p>Emits warnings for unused imported functions. 
	    Default is to emit no warnings for unused imported functions.</p>
          </item>

          <tag><c>nowarn_underscore_match</c></tag>
          <item>
            <p>By default, warnings are emitted when a variable that begins
              with an underscore is matched after being bound. Use this
              option to turn off this kind of warning.</p>
          </item>

          <tag><c>nowarn_unused_vars</c></tag>
          <item>
            <p>By default, warnings are emitted for unused variables,
	      except for variables beginning with an underscore 
	      ("Prolog style warnings").
              Use this option to turn off this kind of warning.</p>
          </item>

	  <tag><c>nowarn_unused_record</c></tag>
          <item>
            <p>Turns off warnings for unused record definitions. Default is to
	    emit warnings for unused locally defined records.</p>
          </item>

	  <tag><c>{nowarn_unused_record, RecordNames}</c></tag>
          <item>
            <p>Turns off warnings for unused record definitions. Default is to
	    emit warnings for unused locally defined records.</p>
          </item>

	  <tag><c>nowarn_unused_type</c></tag>
          <item>
            <p>Turns off warnings for unused type declarations. Default is to
	    emit warnings for unused local type declarations.</p>
          </item>

          <tag><c>nowarn_nif_inline</c></tag>
          <item>
              <p>By default, warnings are emitted when inlining is enabled in
                a module that may load NIFs, as the compiler may inline NIF
                fallbacks by accident. Use this option to turn off this kind of
                warnings.</p>
          </item>

          <tag><c>warn_missing_spec</c></tag>
          <item>
              <p>By default, warnings are not emitted when a specification
                (or contract) for an exported function is not given. Use this
                option to turn on this kind of warning.</p>
          </item>

          <tag><c>warn_missing_spec_all</c></tag>
          <item>
              <p>By default, warnings are not emitted when a specification
                (or contract) for an exported or unexported function is not
                given. Use this option to turn on this kind of warning.</p>
          </item>
        </taglist>

	<p>Other kinds of warnings are <em>opportunistic
	warnings</em>. They are generated when the compiler happens to
	notice potential issues during optimization and code
	generation.</p>

	<note>
	  <p>The compiler does not warn for expressions that it
          does not attempt to optimize. For example, the compiler will
          emit a warning for <c>1/0</c> but not for <c>X/0</c>,
          because <c>1/0</c> is a constant expression that the compiler
          will attempt to evaluate.</p>

          <p>The absence of warnings does not mean that there are no
          remaining errors in the code.</p>
        </note>

        <p>Opportunistic warnings can be disabled using the following
        options:</p>

        <taglist>
          <tag><c>nowarn_opportunistic</c></tag>
          <item><p>Disable all opportunistic warnings.</p></item>

          <tag><c>nowarn_failed</c></tag>
          <item><p>Disable warnings for expressions that will always
          fail (such as <c>atom+42</c>).</p></item>

          <tag><c>nowarn_ignored</c></tag>
          <item><p>Disable warnings for expressions whose
          values are ignored.</p></item>

          <tag><c>nowarn_nomatch</c></tag>
          <item><p>Disable warnings for patterns that will never match
          (such as <c>a=b</c>) and for guards that always evaluate to
          <c>false</c>.</p></item>
        </taglist>

	<note>
	<p>All options, except the include path
	  (<c>{i,Dir}</c>), can also be given in the file with attribute
	  <c>-compile([Option,...])</c>.
	  Attribute <c>-compile()</c> is allowed after the function
	  definitions.</p>
	</note>
	
	<note>
	<p>Before OTP 22, the option <c>{nowarn_deprecated_function,
	MFAs}</c> was only recognized when given in the file with
	attribute <c>-compile()</c>. (The option
	<c>{nowarn_unused_function,FAs}</c> was incorrectly documented
	to only work in a file, but it also worked when given in the
	option list.) Starting from OTP 22, all options that can be
	given in the file can also be given in the option list.</p>
	</note>

        <p>For debugging of the compiler, or for pure curiosity,
          the intermediate code generated by each compiler pass can be
	  inspected.
          To print a complete list of the options to produce list files,
	  type <c>compile:options()</c> at the Erlang shell prompt.
          The options are printed in the order that the passes are
	  executed. If more than one listing option is used, the one
	  representing the earliest pass takes effect.</p>

        <p>Unrecognized options are ignored.</p>

        <p>Both <c>WarningList</c> and <c>ErrorList</c> have
	  the following format:</p>
        <code>
[{FileName,[ErrorInfo]}].</code>

	<p><c>ErrorInfo</c> is described later in this section. 
	The filename is included here, as the compiler uses the 
	Erlang pre-processor <c>epp</c>, which allows the code to be 
	included in other files. It is therefore important to know to
	  <em>which</em> file the location of an error or a warning refers.
	</p>
      </desc>
    </func>

    <func>
      <name since="">forms(Forms)</name>
      <fsummary>Compiles a list of forms.</fsummary>
      <desc>
        <p>Is the same as
	  <c>forms(Forms, [verbose,report_errors,report_warnings])</c>.
	</p>
      </desc>
    </func>

    <func>
      <name since="">forms(Forms, Options) -> CompRet</name>
      <fsummary>Compiles a list of forms.</fsummary>
      <type>
        <v>Forms = <seetype marker="#forms">forms()</seetype></v>
        <v>forms() = [<seetype marker="stdlib:erl_parse#abstract_form">erl_parse:abstract_form</seetype>] | <seeerl marker="cerl#type-c_module">cerl:c_module()</seeerl></v>
        <v>Options = [<seetype marker="#option">option()</seetype>]</v>
        <v>CompRet = BinRet | ErrRet</v>
        <v>BinRet = {ok,ModuleName,BinaryOrCode} | {ok,ModuleName,BinaryOrCode,Warnings}</v>
        <v>ModuleName = module()</v>
        <v>BinaryOrCode = binary() | term()</v>
        <v>ErrRet = error | {error,Errors,Warnings}</v>
        <v>Warnings = Errors = [{<seetype marker="kernel:file#filename">file:filename()</seetype>, [{<seetype marker="stdlib:erl_anno#location">erl_anno:location()</seetype> | 'none', module(), term()}]}]</v>
      </type>
      <desc>
        <p>Analogous to <c>file/1</c>, but takes a list of forms (in
	  either Erlang abstract or Core Erlang format representation)
      as first argument.
          Option <c>binary</c> is implicit, that is, no object code
	  file is produced. For options that normally produce a listing 
	  file, such as 'E', the internal format for that compiler pass 
	  (an Erlang term, usually not a binary) is returned instead of 
	a binary.</p>
      </desc>
    </func>

    <func>
      <name since="">format_error(ErrorDescriptor) -> chars()</name>
      <fsummary>Formats an error descriptor.</fsummary>
      <type>
        <v>ErrorDescriptor = errordesc()</v>
      </type>
      <desc>
        <p>Uses an <c>ErrorDescriptor</c> and returns a deep list of
	  characters that describes the error. This function is
	  usually called implicitly when an <c>ErrorInfo</c> structure 
	(described in section 
	<seeerl marker="#error_information">Error Information</seeerl>) is processed.</p>
      </desc>
    </func>

    <func>
      <name since="">output_generated(Options) -> true | false</name>
      <fsummary>Determines whether the compiler generates an output file.</fsummary>
      <type>
        <v>Options = [term()]</v>
      </type>
      <desc>
        <p>Determines whether the compiler generates a <c>beam</c>
	file with the given options. <c>true</c> means that a <c>beam</c>
	file is generated. <c>false</c> means that the compiler
	generates some listing file, returns a binary, or merely
	checks the syntax of the source code.</p>
      </desc>
    </func>

    <func>
      <name since="">noenv_file(File, Options) -> CompRet</name>
      <fsummary>Compiles a file (ignoring <c>ERL_COMPILER_OPTIONS)</c>.</fsummary>
      <desc>
      <p>Works like <seemfa marker="#file/2">file/2</seemfa>,
	 except that the environment variable <c>ERL_COMPILER_OPTIONS</c>
	 is not consulted.</p>
      </desc>
    </func>

    <func>
      <name since="">noenv_forms(Forms, Options) -> CompRet</name>
      <fsummary>Compiles a list of forms (ignoring <c>ERL_COMPILER_OPTIONS)</c>.</fsummary>
      <desc>
        <p>Works like <seemfa marker="#forms/2">forms/2</seemfa>,
	 except that the environment variable <c>ERL_COMPILER_OPTIONS</c>
	 is not consulted.</p>
      </desc>
    </func>

    <func>
      <name since="">noenv_output_generated(Options) -> true | false</name>
      <fsummary>Determines whether the compiler generates an output file 
      (ignoring <c>ERL_COMPILER_OPTIONS)</c>.</fsummary>
      <type>
        <v>Options = [term()]</v>
      </type>
      <desc>
        <p>Works like
	<seemfa marker="#output_generated/1">output_generated/1</seemfa>,
	except that the environment variable <c>ERL_COMPILER_OPTIONS</c>
	is not consulted.</p>
      </desc>
    </func>

  </funcs>

  <section>
    <title>Default Compiler Options</title>
    <p>The (host operating system) environment variable
      <c>ERL_COMPILER_OPTIONS</c> can be used to give default compiler
      options. Its value must be a valid Erlang term. If the value is a
      list, it is used as is. If it is not a list, it is put
      into a list.</p>

      <p>The list is appended to any options given to
      <seemfa marker="#file/2">file/2</seemfa>,
      <seemfa marker="#forms/2">forms/2</seemfa>, and
      <seemfa marker="#output_generated/1">output_generated/2</seemfa>.
      Use the alternative functions
      <seemfa marker="#noenv_file/2">noenv_file/2</seemfa>,
      <seemfa marker="#noenv_forms/2">noenv_forms/2</seemfa>, or
      <seemfa marker="#noenv_output_generated/1">noenv_output_generated/2</seemfa>
      if you do not want the environment variable to be consulted,
      for example, if you are calling the compiler recursively from
      inside a parse transform.</p>

      <p>The list can be retrieved with
      <seemfa marker="#env_compiler_options/0">env_compiler_options/0</seemfa>.</p>
  </section>

  <section>
    <title>Inlining</title>
    <p>The compiler can do function inlining within an Erlang
      module. Inlining means that a call to a function is replaced with
      the function body with the arguments replaced with the actual
      values. The semantics are preserved, except if exceptions are
      generated in the inlined code. Exceptions are reported as
      occurring in the function the body was inlined into. Also,
      <c>function_clause</c> exceptions are converted to similar
      <c>case_clause</c> exceptions.</p>

    <p>When a function is inlined, the original function is
      kept if it is exported (either by an explicit export or if the
      option <c>export_all</c> was given) or if not all calls to the
      function are inlined.</p>
    
    <p>Inlining does not necessarily improve running time.
      For example, inlining can increase Beam stack use, which
      probably is detrimental to performance for recursive functions.
    </p>

    <p>Inlining is never default. It must be explicitly enabled with a
      compiler option or a <c>-compile()</c> attribute in the source
      module.</p>

    <p>To enable inlining, either use the option <c>inline</c> to
    let the compiler decide which functions to inline, or
    <c>{inline,[{Name,Arity},...]}</c> to have the compiler inline
    all calls to the given functions. If the option is given inside
    a <c>compile</c> directive in an Erlang module, <c>{Name,Arity}</c>
    can be written as <c>Name/Arity</c>.</p>

    <p>Example of explicit inlining:</p>

    <pre>
-compile({inline,[pi/0]}).

pi() -> 3.1416.
    </pre>

    <p>Example of implicit inlining:</p>
    <pre>
-compile(inline).</pre>

    <p>The option <c>{inline_size,Size}</c> controls how large functions
      that are allowed to be inlined. Default is <c>24</c>, which
      keeps the size of the inlined code roughly the same as
      the un-inlined version (only relatively small functions are
      inlined).</p>

    <p>Example:</p>
    <pre>
%% Aggressive inlining - will increase code size.
-compile(inline).
-compile({inline_size,100}).</pre>
  </section>

  <section>
    <title>Inlining of List Functions</title>
    <p>The compiler can also inline various list manipulation functions
      from the module <c>list</c> in STDLIB.</p>

    <p>This feature must be explicitly enabled with a compiler option or a
      <c>-compile()</c> attribute in the source module.</p>

    <p>To enable inlining of list functions, use option <c>inline_list_funcs</c>.</p>

    <p>The following functions are inlined:</p>
    <list type="bulleted">
      <item><seemfa marker="stdlib:lists#all/2">lists:all/2</seemfa></item>
      <item><seemfa marker="stdlib:lists#any/2">lists:any/2</seemfa></item>
      <item><seemfa marker="stdlib:lists#foreach/2">lists:foreach/2</seemfa></item>
      <item><seemfa marker="stdlib:lists#map/2">lists:map/2</seemfa></item>
      <item><seemfa marker="stdlib:lists#flatmap/2">lists:flatmap/2</seemfa></item>
      <item><seemfa marker="stdlib:lists#filter/2">lists:filter/2</seemfa></item>
      <item><seemfa marker="stdlib:lists#foldl/3">lists:foldl/3</seemfa></item>
      <item><seemfa marker="stdlib:lists#foldr/3">lists:foldr/3</seemfa></item>
      <item><seemfa marker="stdlib:lists#mapfoldl/3">lists:mapfoldl/3</seemfa></item>
      <item><seemfa marker="stdlib:lists#mapfoldr/3">lists:mapfoldr/3</seemfa></item>
    </list>
  </section>

  <section>
    <title>Parse Transformations</title>

    <p>Parse transformations are used when a programmer wants to use
      Erlang syntax but with different semantics. The original Erlang
      code is then transformed into other Erlang code.</p>

    <p>See <seeerl marker="stdlib:erl_id_trans">erl_id_trans(3)</seeerl>
      for an example and an explanation of the function
      <c>parse_transform_info/0</c>.</p>
  </section>

  <section>
    <marker id="error_information"></marker>
    <title>Error Information</title>

    <p>The <c>ErrorInfo</c> mentioned earlier is the standard
      <c>ErrorInfo</c> structure, which is returned from all I/O modules.
      It has the following format:</p>
    <code>
{ErrorLocation, Module, ErrorDescriptor}</code>

    <p><c>ErrorLocation</c> is the atom <c>none</c> if the error does
    not correspond to a specific location, for example, if the source file does
    not exist.</p>

    <p>A string describing the error is obtained with the following
      call:</p>
    <code>
Module:format_error(ErrorDescriptor)</code>
  </section>

  <section>
    <title>See Also</title>
    <p>
      <seeerl marker="stdlib:epp">epp(3)</seeerl>,
      <seeerl marker="stdlib:erl_id_trans">erl_id_trans(3)</seeerl>,
      <seeerl marker="stdlib:erl_lint">erl_lint(3)</seeerl>,
      <seeerl marker="stdlib:beam_lib">beam_lib(3)</seeerl>
    </p>
  </section>
</erlref>