f98d50d94f34e6d15feb8238b224c6464e3c4b74
[nit.git] / share / man / nitc.md
1 % NITG(1)
2
3 # NAME
4
5 nitc - compiles Nit programs.
6
7
8 # SYNOPSIS
9
10 nitc [*options*] FILE...
11
12
13 # DESCRIPTION
14
15 nitc is the current official Nit compiler.
16 It takes the main module of a Nit program as argument and produces an executable file.
17
18 By default, the generated executables are produced in the current directory.
19 (see `--dir` for details.)
20
21 Internally, nitc rely on the presence of a C compiler. Usually gcc (but nitc was successfully tested with clang).
22 A compilation directory is therefore created and (re-)used.
23 By default, the compilation directory is named `.nit_compile`.
24 (see `--compile-dir` for details.)
25
26 Currently, because Nit is still in heavy development, the compilation directory is not cleaned after the compilation.
27
28 By default, the compilation process tries to have a good trade-off between the compilation time and the performance of produced executables.
29 To produce more optimized executables, the current best option is `--semi-global`.
30
31 To improve the compilation time and simplify the compilation of multiple programs, more than one file can be given.
32 Each one will be compiled into a distinct executable.
33
34     $ nitc prog1.nit prog2.nit
35
36 To combine files into a single program, use the `-m` option.
37
38     $ nitc prog1.nit -m other_module.nit
39
40 nitc can produces executables for various platforms when specific modules are used.
41 Currently, android, pnacl and emscripten are supported.
42 See the documentation of these specific modules for details.
43
44
45 # OPTIONS
46
47 ## MESSAGES
48
49 `-W`, `--warn`
50 :   Show additional warnings (advices).
51
52     By default, only important warnings are displayed.
53     May be overridden by `-w`.
54
55     Important warnings are displayed by default. A warning is considered important when:
56
57      * There is a simple correction.
58      * There is no reason to let the code this way.
59      * There is always a real issue (no false positive).
60
61     Other warnings, called advices, are not displayed by default to avoid filling the terminal with
62     unwanted information.
63     A warning is considered an advice when:
64
65      * The correction could be complex. e.g. require a refactorisation or an API change.
66      * The correction cannot be done. e.g. Code that use a deprecated API for some compatibility reason.
67      * There is not a real issue (false positive). Note that this should be unlikely.
68      * Transitional: While a real important warning, it fires a lot in current code, so a transition is needed
69        in order to let people fix them before promoting the advice to an important warning.
70
71 `-w`, `--warning`
72 :   Show/hide a specific warning.
73
74     Each type of warning can be individually displayed or hidden.
75     The `-w` option takes the name of a warning (displayed at the end of the warning message, between parentheses) to activate it;
76     and "no-{name}" to disable it.
77     It has precedence over -q and -W.
78     Multiple `-w` can be given.
79
80     To show only `missing-doc` warnings in standard"
81
82         $ nitc -q -w missing-doc standard
83
84     To show all warnings and advices, except `missing-doc`:
85
86         $ nitc -W -w no-missing-doc standard
87
88     To show important warnings except `useless-type-test`, but not advice except `missing-doc`:
89
90         $ nitc -w missing-doc -w no-useless-type-test standard
91
92 `-q`, `--quiet`
93 :   Do not show warnings.
94     May be overridden by `-w`
95
96 `--stop-on-first-error`
97 :   Just display the first encountered error then stop.
98
99     By default, nitc tries to detect and display more than one error before aborting the compilation.
100
101 `--no-color`
102 :   Do not use color to display errors and warnings.
103
104     Also, do not echo the line.
105     This options is mainly used by scripts and tools that need parsable error messages.
106
107 `-v`, `--verbose`
108 :   Additional messages from the tool.
109     Multiple `-v` can be given to improve the verbosity.
110
111     With one `-v`, there is constant number of lines.
112     With two `-v`, the number of lines is proportional to the number of modules.
113     With three `-v`, the number of lines is proportional to the number of definition of classes.
114     With four `-v`, the number of lines is proportional to the number of definition of properties.
115
116 `--log`
117 :   Generate various log files.
118     Currently unused.
119
120 `--log-dir`
121 :   Directory where to generate log files.
122     Currently unused.
123
124
125 `-h`, `-?`, `--help`
126 :   Show Help (the list of options).
127
128 `--version`
129 :   Show version and exit.
130
131
132 ## PATHS
133
134 `-I`, `--path`
135 :   Add an additional include path.
136
137     This option is used to indicate an additional path of a directory containing Nit libraries.
138
139     The path added with `-I` are searched before those added by the environment variable `NIT_PATH`.
140
141     May be used more than once.
142
143 `-o`, `--output`
144 :   Output executable name.
145
146     Indicates the path and name of the produced executable.
147
148     Note: it is better to use `--dir` if only the directory is important.
149     This way, the platform extension will be correctly set.
150
151     `-o` is not usable if multiple programs are compiled at once.
152
153 `--dir`
154 :   Output directory.
155
156     Produce the executables in the given directory instead of the current directory.
157
158 `--nit-dir`
159 :   Base directory of the Nit installation.
160
161     Has precedence over the environment variable `NIT_DIR`.
162
163 ## COMPILATION
164
165 `--compile-dir`
166 :   Directory used to generate temporary files.
167
168     By default, it is named `.nit_compile`.
169
170 `--no-cc`
171 :   Do not invoke the C compiler.
172
173     Files in the compilation directory are generated but the C compiler is not invoked.
174
175     This option is mainly used to produce C files distributable then compilable on system that do not have a Nit compiler (e.g. embedded system).
176     In this case, it is suggested to also use the options `--dir`, `--compile-dir` and `--semi-global`.
177
178         $ nitc examples/hello_world.nit --no-cc --dir hello --compile-dir hello --semi-global
179
180     Will produce a `hello` directory that contains the required C files to finish the compilation.
181     Only the C files required for the program are generated.
182     The final binary will be generated in the same directory.
183
184 `-m`
185 :   Additional module to mix-in.
186
187     Additional modules are imported and refine the main module of the program.
188     This has basically the same effect than implementing a specific module that imports the main module of the program then each one of the mix-in modules.
189     May be used more than once.
190
191     This is option is used to weave additional behaviors to existing programs.
192     Modules designated to bring features to programs by refining basic or specialized services, without any intervention of the main program, are good candidates to be used with the `-m` option.
193     E.g. `hash_debug`.
194
195     An other usage of the `-m` option is to compile program to a specific platform. E.g. `emscripten`  or `android`.
196
197     A last usage is to develop programs as product lines with a main basic module (vanilla) and specific distinct features as flavor modules, then to combine them at compile-time.
198
199         $ nitc prog_vanilla.nit -m feature_chocolate.nit -m feature_cherry.nit
200
201 `-D`, `--define`
202 :   Define a specific property.
203
204     The `-D` option allows to refine a top-level method at compile-time.
205     This has basically the same effect than implementing a specific module that imports the main module of the program and refines the designated methods.
206
207     The designated method must be top-level function with no parameters that returns a Bool, an Int or a String.
208
209     The argument of the `-D` option is "{name}={value}".
210     For Bool, the argument can also be just "{name}", in this case, the value is considered to be `true`.
211
212         $ nitc foo.nit -D prefix=/opt/foo -D port=8080 -D with_ssl
213
214 `--release`
215 :   Compile in release mode and finalize application.
216
217     Currently, this only affect the android platform.
218
219 ## COMPILATION MODES
220
221 `nitc` includes distinct compilation modes.
222
223 `--separate`
224 :   Use separate compilation (default mode).
225
226     In separate compilation, modules are compiled independently of their programs.
227     This makes the recompilation of programs faster since only the modified files need to be recompiled.
228
229 `--global`
230 :   Use global compilation.
231
232     The produced executables may become huge and the compilation time is prohibitive.
233     But sometime, they are faster.
234
235     In practice, `--semi-global` produces nearly as fast but smaller executables.
236
237 `--erasure`
238 :   Erase generic types.
239
240     Like `--separate` but use an erasure dynamic typing policy for generics and virtual types.
241     Usually you do not need this, even if you understand the previous sentence.
242
243
244 ## SEMI-GLOBAL OPTIMIZATIONS
245
246 In `--separate` and in `--erasure` modes, some optimization can be gained by relaxing the constraint about
247 the independence on programs.
248
249 Therefore, with these options, the produced executables may be faster and smaller but the recompilation time
250 will increase.
251
252 `--semi-global`
253 :   Enable all semi-global optimizations.
254
255 `--rta`
256 :   Activate RTA (Rapid Type Analysis).
257
258     This option only make sense in `--erasure` to enable some semi-global optimizations.
259
260     RTA is implicitly enabled in `--separate` and `--global`.
261
262 `--inline-coloring-numbers`
263 :   Inline colors and ids (semi-global).
264
265 `--inline-some-methods`
266 :   Allow the separate compiler to inline some methods (semi-global).
267     Need `--rta`.
268
269 `--direct-call-monomorph`
270 :   Allow the separate compiler to direct call monomorphic sites (semi-global).
271     Need `--rta`.
272
273 `--skip-dead-methods`
274 :   Do not compile dead methods (semi-global).
275     Need `--rta`.
276
277
278 ## DANGEROUS OPTIMIZATIONS
279
280 The following optimizations disable runtime checks.
281 It means that correct (non-buggy) programs may be slightly faster.
282 It also means that incorrect (buggy) programs may have unspecified behaviors
283 (e.g. formatting your hard drive or killing your cat).
284
285 In fact, these options are mainly used to bench the compilation results.
286
287 `--no-check-all`
288 :   Disable all tests (dangerous).
289
290 `--no-check-covariance`
291 :   Disable type tests of covariant parameters (dangerous).
292
293 `--no-check-attr-isset`
294 :   Disable isset tests before each attribute access (dangerous).
295
296 `--no-check-assert`
297 :   Disable the evaluation of explicit `assert` and `as` (dangerous).
298
299 `--no-check-autocast`
300 :   Disable implicit casts on unsafe expression usage (dangerous).
301
302 `--no-check-null`
303 :   Disable tests of null receiver (dangerous).
304
305 `--no-check-erasure-cast`
306 :   Disable implicit casts on unsafe return with erasure-typing policy (dangerous).
307
308
309 ## UNOPTIMIZATIONS
310
311 These options are used to debug or to bench the compilation results.
312 Usually you do not need them since they make the generated code slower.
313
314 `--hardening`
315 :   Generate contracts in the C code against bugs in the compiler.
316
317 `--no-shortcut-range`
318 :   Always instantiate a range and its iterator on 'for' loops.
319
320 `--no-union-attribute`
321 :   Put primitive attributes in a box instead of an union.
322
323 `--no-shortcut-equal`
324 :   Always call == in a polymorphic way.
325
326 `--no-inline-intern`
327 :   Do not inline call to intern methods.
328
329 `--colo-dead-methods`
330 :   Force colorization of dead methods.
331
332 `--colors-are-symbols`
333 :   Store colors as symbols instead of static data.
334
335     By default, the various identifiers used to implement OO-mechanisms are stored as genuine constant static variables.
336
337     This option uses linker symbols to encode these identifiers.
338     This makes the compiled program faster since less indirections are required to get the values.
339     It also produces executables that are a little bit smaller since static memory does not have to store the colors.
340
341     Warning: the usage of linker symbols is not portable on all toolchains (eg. Mac OS X).
342     Also, this option does nothing on some platforms (like android).
343
344 `--no-gcc-directive`
345 :   Disable advanced gcc directives for optimization.
346
347
348 ## INTERNAL OPTIONS
349
350 These options can be used to control the fine behavior of the tool.
351 They are useless for a normal user.
352
353 `--disable-phase`
354 :   Disable a specific phase; use `list` to get the list.
355
356 `--only-parse`
357 :   Only proceed to parse files.
358
359 `--only-metamodel`
360 :   Stop after meta-model processing.
361
362 `--ignore-visibility`
363 :   Do not check, and produce errors, on visibility issues.
364
365 `--no-main`
366 :   Do not generate main entry point.
367
368 `--stacktrace`
369 :   Control the generation of stack traces.
370
371 `--max-c-lines`
372 :   Maximum number of lines in generated C files. Use 0 for unlimited.
373
374 `--group-c-files`
375 :   Group all generated code in the same series of files.
376
377 `--make-flags`
378 :   Additional options to the `make` command.
379
380           $ nitc foo.nit --make-flags 'CC=clang' --make-flags 'CFLAGS="-O0 -g"'
381
382 `--typing-test-metrics`
383 :   Enable static and dynamic count of all type tests.
384
385 `--invocation-metrics`
386 :   Enable static and dynamic count of all method invocations.
387
388 `--isset-checks-metrics`
389 :   Enable static and dynamic count of isset checks before attributes access.
390
391 `--tables-metrics`
392 :   Enable static size measuring of tables used for vft, typing and resolution.
393
394 `--set-dummy-tool`
395 :   Set toolname and version to DUMMY. Useful for testing.
396
397 `--bash-completion`
398 :   Generate bash_completion file for this program.
399
400 `--stub-man`
401 :   Generate a stub manpage in pandoc markdown format.
402
403
404 # ENVIRONMENT VARIABLES
405
406 `NIT_DIR`
407 :   Base directory of the Nit installation.
408
409     When the `NIT_DIR` environment variable is set then it specifies the path of the Nit install directory.
410
411     This directory is used to locate binaries, shared files and the common libraries.
412
413     When unset, the directory is guessed according to some heuristic.
414
415     The `--nit-dir` option also set the base directory of the Nit installation but has precedence.
416
417 `NIT_PATH`
418 :   Additional include paths.
419
420     The `NIT_PATH` environment variable contains paths of directories containing Nit libraries.
421     Each path is separated with a column (`:`).
422
423     The `-I` option also add additional paths.
424
425 `NIT_GC_OPTION`
426 :   Runtime control of the garbage collector.
427
428     The behavior of the GC of the executables produced by nitc can be tuned with this environment variable.
429
430     The environment variable is used when programs are executed, not when they are compiled.
431     Thus, you do not need to recompile programs in order to tweak their GC options.
432
433     Available values are:
434
435     * boehm: use the Boehm-Demers-Weiser's conservative garbage collector (default).
436     * malloc: disable the GC and just use `malloc` without doing any `free`.
437     * large: disable the GC and just allocate a large memory area to use for all instantiation.
438     * help: show the list of available options.
439
440 # SEE ALSO
441
442 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>