nit: Added link to `CONTRIBUTING.md` from the README
[nit.git] / share / man / nitc.md
1 # NAME
2
3 nitc - compiles Nit programs.
4
5
6 # SYNOPSIS
7
8 nitc [*options*] FILE...
9
10
11 # DESCRIPTION
12
13 nitc is the current official Nit compiler.
14 It takes the main module of a Nit program as argument and produces an executable file.
15
16 By default, the generated executables are produced in the current directory.
17 (see `--dir` for details.)
18
19 Internally, nitc rely on the presence of a C compiler. Usually gcc (but nitc was successfully tested with clang).
20 A compilation directory is therefore created and (re-)used.
21 By default, the compilation directory is named `nit_compile` and is removed after the compilation.
22 (see `--compile-dir` for details.)
23
24 Currently, because Nit is still in heavy development, the compilation directory is not cleaned after the compilation.
25
26 By default, the compilation process tries to have a good trade-off between the compilation time and the performance of produced executables.
27 To produce more optimized executables, the current best option is `--semi-global`.
28
29 To improve the compilation time and simplify the compilation of multiple programs, more than one file can be given.
30 Each one will be compiled into a distinct executable.
31
32     $ nitc prog1.nit prog2.nit
33
34 To combine files into a single program, use the `-m` option.
35
36     $ nitc prog1.nit -m other_module.nit
37
38 nitc can produces executables for various platforms when specific modules are used.
39 Currently, android, pnacl and emscripten are supported.
40 See the documentation of these specific modules for details.
41
42
43 # OPTIONS
44
45 ## MESSAGES
46
47 ### `-W`, `--warn`
48 Show additional warnings (advices).
49
50 By default, only important warnings are displayed.
51 May be overridden by `-w`.
52
53 Important warnings are displayed by default. A warning is considered important when:
54
55 * There is a simple correction.
56 * There is no reason to let the code this way.
57 * There is always a real issue (no false positive).
58
59 Other warnings, called advices, are not displayed by default to avoid filling the terminal with
60 unwanted information.
61 A warning is considered an advice when:
62
63 * The correction could be complex. e.g. require a refactorisation or an API change.
64 * The correction cannot be done. e.g. Code that use a deprecated API for some compatibility reason.
65 * There is not a real issue (false positive). Note that this should be unlikely.
66 * Transitional: While a real important warning, it fires a lot in current code, so a transition is needed
67 in order to let people fix them before promoting the advice to an important warning.
68
69 ### `-w`, `--warning`
70 Show/hide a specific warning.
71
72 Each type of warning can be individually displayed or hidden.
73 The `-w` option takes the name of a warning (displayed at the end of the warning message, between parentheses) to activate it;
74 and "no-{name}" to disable it.
75 It has precedence over -q and -W.
76 Multiple `-w` can be given.
77
78 To show only `missing-doc` warnings in standard"
79
80     $ nitc -q -w missing-doc standard
81
82 To show all warnings and advices, except `missing-doc`:
83
84     $ nitc -W -w no-missing-doc standard
85
86 To show important warnings except `useless-type-test`, but not advice except `missing-doc`:
87
88     $ nitc -w missing-doc -w no-useless-type-test standard
89
90 ### `-q`, `--quiet`
91 Do not show warnings.
92 May be overridden by `-w`
93
94 ### `--stop-on-first-error`
95 Just display the first encountered error then stop.
96
97 By default, nitc tries to detect and display more than one error before aborting the compilation.
98
99 ### `--no-color`
100 Do not use color to display errors and warnings.
101
102 Also, do not echo the line.
103 This options is mainly used by scripts and tools that need parsable error messages.
104
105 ### `-v`, `--verbose`
106 Additional messages from the tool.
107 Multiple `-v` can be given to improve the verbosity.
108
109 With one `-v`, there is constant number of lines.
110 With two `-v`, the number of lines is proportional to the number of modules.
111 With three `-v`, the number of lines is proportional to the number of definition of classes.
112 With four `-v`, the number of lines is proportional to the number of definition of properties.
113
114 ### `--log`
115 Generate various log files.
116
117 The tool will generate some files in the logging directory (see `--log-dir`).
118 These files are intended to the advanced user and the developers of the tools.
119
120 ### `--log-dir`
121 Directory where to generate log files.
122
123 By default the directory is called `logs` in the working directory.
124
125
126 ### `-h`, `-?`, `--help`
127 Show Help (the list of options).
128
129 ### `--version`
130 Show version and exit.
131
132
133 ## PATHS
134
135 ### `-I`, `--path`
136 Add an additional include path.
137
138 This option is used to indicate an additional path of a directory containing Nit libraries.
139
140 The path added with `-I` are searched before those added by the environment variable `NIT_PATH`.
141
142 May be used more than once.
143
144 ### `-o`, `--output`
145 Filename of the generated executable.
146
147 Indicates the path and name of the produced executable.
148
149 Note: it is better to use `--dir` if only the directory is important.
150 This way, the platform extension will be correctly set.
151
152 `-o` is not usable if multiple programs are compiled at once.
153
154 ### `--dir`
155 Output directory.
156
157 Produce the executables in the given directory instead of the current directory.
158
159 ### `--nit-dir`
160 Base directory of the Nit installation.
161
162 Has precedence over the environment variable `NIT_DIR`.
163
164 ## COMPILATION
165
166 ### `--compile-dir`
167 Directory used to generate temporary files.
168
169 By default, it is named `nit_compile` and created in the current directory and destroyed after the compilation.
170
171 If the option `--compile_dir` or `--no-cc` is used, then the directory is not destroyed and let as is.
172
173 ### `--no-cc`
174 Do not invoke the C compiler.
175
176 Files in the compilation directory are generated but the C compiler is not invoked.
177
178 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).
179 In this case, it is suggested to also use the options `--dir`, `--compile-dir` and `--semi-global`.
180
181     $ nitc examples/hello_world.nit --no-cc --dir hello --compile-dir hello --semi-global
182
183 Will produce a `hello` directory that contains the required C files to finish the compilation.
184 Only the C files required for the program are generated.
185 The final binary will be generated in the same directory.
186
187 Note that, to be useful, the compilation directory is not destroyed when `--no-cc` is used.
188
189 ### `-m`, `--mixin`
190 Additional module to mix-in.
191
192 Additional modules are imported and refine the main module of the program.
193 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.
194 May be used more than once.
195
196 This is option is used to weave additional behaviors to existing programs.
197 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.
198 E.g. `hash_debug`.
199
200 An other usage of the `-m` option is to compile program to a specific platform. E.g. `emscripten`  or `android`.
201
202 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.
203
204     $ nitc prog_vanilla.nit -m feature_chocolate.nit -m feature_cherry.nit
205
206 ### `-D`, `--define`
207 Define a specific property.
208
209 The `-D` option allows to refine a top-level method at compile-time.
210 This has basically the same effect than implementing a specific module that imports the main module of the program and refines the designated methods.
211
212 The designated method must be top-level function with no parameters that returns a Bool, an Int or a String.
213
214 The argument of the `-D` option is "{name}={value}".
215 For Bool, the argument can also be just "{name}", in this case, the value is considered to be `true`.
216
217     $ nitc foo.nit -D prefix=/opt/foo -D port=8080 -D with_ssl
218
219 ### `--release`
220 Compile in release mode and finalize application.
221
222 Currently, this only affect the android platform.
223
224 ### `-g`, `--debug`
225 Compile in debug mode.
226
227 Currently removes gcc optimizations.
228 Also preserves the source-files directory for C-debuggers.
229
230 For more debugging-related options, see also `--hardening` and `NIT_GC_OPTION`
231
232 ## COMPILATION MODES
233
234 ### `nitc` includes distinct compilation modes.
235
236 ### `--separate`
237 Use separate compilation (default mode).
238
239 In separate compilation, modules are compiled independently of their programs.
240 This makes the recompilation of programs faster since only the modified files need to be recompiled.
241
242 ### `--global`
243 Use global compilation.
244
245 The produced executables may become huge and the compilation time is prohibitive.
246 But sometime, they are faster.
247
248 In practice, `--semi-global` produces nearly as fast but smaller executables.
249
250 ### `--erasure`
251 Erase generic types.
252
253 Like `--separate` but use an erasure dynamic typing policy for generics and virtual types.
254 Usually you do not need this, even if you understand the previous sentence.
255
256
257 ## SEMI-GLOBAL OPTIMIZATIONS
258
259 In `--separate` and in `--erasure` modes, some optimization can be gained by relaxing the constraint about
260 the independence on programs.
261
262 Therefore, with these options, the produced executables may be faster and smaller but the recompilation time
263 will increase.
264
265 ### `--semi-global`
266 Enable all semi-global optimizations.
267
268 ### `--rta`
269 Activate RTA (Rapid Type Analysis).
270
271 This option only make sense in `--erasure` to enable some semi-global optimizations.
272
273 RTA is implicitly enabled in `--separate` and `--global`.
274
275 ### `--inline-coloring-numbers`
276 Inline colors and ids (semi-global).
277
278 ### `--inline-some-methods`
279 Allow the separate compiler to inline some methods (semi-global).
280 Need `--rta`.
281
282 ### `--direct-call-monomorph`
283 Allow the separate compiler to direct call monomorphic sites (semi-global).
284 Need `--rta`.
285
286 ### `--direct-call-monomorph0`
287 Allow the separate compiler to direct call monomorphic sites (semi-global).
288 Need `--rta`.
289
290 The difference with the non-zero option is internal:
291 with this option, the monomorphism is looked-at on the mmethod level and not at the callsite level.
292
293 ### `--skip-dead-methods`
294 Do not compile dead methods (semi-global).
295 Need `--rta`.
296
297 ## LINK-BOOST OPTIMIZATIONS
298
299 In `--separate` and in `--erasure` modes, some optimization can be gained by hijacking the linker process.
300
301 Warning: these optimisations are not portable since they use extra features of the GNU linker `ld`.
302 However, there is very few reasons to not use them if GNU `ld` is available.
303
304 ### `--link-boost`
305 Enable all link-boost optimizations.
306
307 ### `--colors-are-symbols`
308 Store colors as symbols instead of static data.
309
310 By default, the various identifiers used to implement OO-mechanisms are stored as genuine constant static variables.
311
312 This option uses linker symbols to encode these identifiers.
313 This makes the compiled program faster since less indirections are required to get the values.
314 It also produces executables that are a little bit smaller since static memory does not have to store the colors.
315
316 ### `--substitute-monomorph`
317 Replace monomorphic trampolines with direct calls.
318
319 Late-binding is implemented with *trampolines*, that are small functions that just select and jump the to right implementations.
320 If, at link-time, is it known that the target will always by the same implementation then all calls to the trampoline are replaced by
321 direct calls to this single implementation.
322
323 Note that using trampolines as indirection slows down the executable.
324 However, it is expected that the gain of monomorphic direct-calls overcompensates the additional indirections in polymorphic trampoline-calls.
325
326 Note: automatically enable option `--trampoline-call`.
327
328 ## POTENTIAL OPTIMIZATIONS
329
330 These optimisation are not enabled by default as they are counter-effective in most cases.
331
332 ### `--guard-call`
333 Guard VFT calls with a direct call.
334
335 ### `--type-poset`
336 Build a poset of types to create more condensed tables.
337
338 The drawback is that more time and memory are used by the compilation process.
339
340
341 ## DANGEROUS OPTIMIZATIONS
342
343 The following optimizations disable runtime checks.
344 It means that correct (non-buggy) programs may be slightly faster.
345 It also means that incorrect (buggy) programs may have unspecified behaviors
346 (e.g. formatting your hard drive or killing your cat).
347
348 In fact, these options are mainly used to bench the compilation results.
349
350 ### `--no-check-all`
351 Disable all tests (dangerous).
352
353 ### `--no-check-covariance`
354 Disable type tests of covariant parameters (dangerous).
355
356 ### `--no-check-attr-isset`
357 Disable isset tests before each attribute access (dangerous).
358
359 ### `--no-check-assert`
360 Disable the evaluation of explicit `assert` and `as` (dangerous).
361
362 ### `--no-check-autocast`
363 Disable implicit casts on unsafe expression usage (dangerous).
364
365 ### `--no-check-null`
366 Disable tests of null receiver (dangerous).
367
368 ### `--no-check-erasure-cast`
369 Disable implicit casts on unsafe return with erasure-typing policy (dangerous).
370
371
372 ## UNOPTIMIZATIONS
373
374 These options are used to debug or to bench the compilation results.
375 Usually you do not need them since they make the generated code slower.
376
377 ### `--hardening`
378 Generate contracts in the C code against bugs in the compiler.
379
380 ### `--no-shortcut-range`
381 Always instantiate a range and its iterator on 'for' loops.
382
383 ### `--no-union-attribute`
384 Put primitive attributes in a box instead of an union.
385
386 ### `--no-shortcut-equal`
387 Always call == in a polymorphic way.
388
389 ### `--no-tag-primitive`
390 Use only boxes for primitive types.
391
392 The separate compiler uses tagged values to encode common primitive types like Int, Bool and Char.
393 This option disables tags and forces such primitive values to be boxed.
394 The drawback is that each boxing costs a memory allocation thus increases the amount of work for the garbage collector.
395
396 However, in some cases, it is possible that this option improves performance since the absence of tags simplify the implementation
397 of OO mechanisms like method calls or equality tests.
398
399 ### `--no-inline-intern`
400 Do not inline call to intern methods.
401
402 ### `--colo-dead-methods`
403 Force colorization of dead methods.
404
405 ### `--no-gcc-directive`
406 Disable advanced gcc directives for optimization.
407
408 ### `--trampoline-call`
409 Use an indirection when calling.
410
411 Just add the trampolines of `--substitute-monomorph` without doing any additionnal optimizations.
412
413 ### `--no-tag-primitives`
414 Use only boxes for primitive types.
415
416 ## INTERNAL OPTIONS
417
418 These options can be used to control the fine behavior of the tool.
419 They are useless for a normal user.
420
421 ### `--disable-phase`
422 Disable a specific phase; use `list` to get the list.
423
424 ### `--only-parse`
425 Only proceed to parse files.
426
427 ### `--only-metamodel`
428 Stop after meta-model processing.
429
430 ### `--ignore-visibility`
431 Do not check, and produce errors, on visibility issues.
432
433 ### `--no-main`
434 Do not generate main entry point.
435
436 ### `--no-stacktrace`
437 Disable the generation of stack traces.
438
439 With this option, the compiled program will not display stack traces on runtime errors.
440
441 Because stack traces rely on libunwind, this option might be useful in order to generate more portable binaries
442 since libunwind might be non available on the runtime system (or available with an ABI incompatible version).
443
444 The generated C is API-portable and can be reused, distributed and compiled on any supported system.
445 If the option `--no-stacktrace` is not used but the development files of the library `libunwind` are not available, then a warning will be displayed
446 and stack trace will be disabled.
447
448 Note that the `--no-stacktrace` option (or this absence) can be toggled manually in the generated Makefile (search `NO_STACKTRACE` in the Makefile).
449 Moreover, the environment variable `NIT_NO_STACK` (see bellow) can also be used at runtime to disable stack traces.
450
451 ### `--max-c-lines`
452 Maximum number of lines in generated C files. Use 0 for unlimited.
453
454 ### `--group-c-files`
455 Group all generated code in the same series of files.
456
457 ### `--make-flags`
458 Additional options to the `make` command.
459
460       $ nitc foo.nit --make-flags 'CC=clang' --make-flags 'CFLAGS="-O0 -g"'
461
462 ### `--typing-test-metrics`
463 Enable static and dynamic count of all type tests.
464
465 ### `--invocation-metrics`
466 Enable static and dynamic count of all method invocations.
467
468 ### `--isset-checks-metrics`
469 Enable static and dynamic count of isset checks before attributes access.
470
471 ### `--tables-metrics`
472 Enable static size measuring of tables used for vft, typing and resolution.
473
474 ### `--set-dummy-tool`
475 Set toolname and version to DUMMY. Useful for testing.
476
477 ### `--bash-completion`
478 Generate bash_completion file for this program.
479
480 ### `--stub-man`
481 Generate a stub manpage in pandoc markdown format.
482
483 ### `--keep-going`
484 Continue after errors, whatever the consequences.
485
486 The tool does not stop after some errors but continue until it produces incorrect result, crashes, erases the hard drive, or just continue forever in an infinite loop.
487 This option is used to test the robustness of the tools by allowing phases to progress on incorrect data.
488
489 ### `--sloppy`
490 Force lazy semantic analysis of the source-code.
491
492 Analysis of methods is thus done only when required.
493 This option breaks the behavior of most of the tools since errors in methods are undetected until the method is required in some processing.
494
495 # ENVIRONMENT VARIABLES
496
497 ### `NIT_DIR`
498 Base directory of the Nit installation.
499
500 When the `NIT_DIR` environment variable is set then it specifies the path of the Nit install directory.
501
502 This directory is used to locate binaries, shared files and the common libraries.
503
504 When unset, the directory is guessed according to some heuristic.
505
506 The `--nit-dir` option also set the base directory of the Nit installation but has precedence.
507
508 ### `NIT_PATH`
509 Additional include paths.
510
511 The `NIT_PATH` environment variable contains paths of directories containing Nit libraries.
512 Each path is separated with a column (`:`).
513
514 The `-I` option also add additional paths.
515
516 ### `NIT_GC_OPTION`
517 Runtime control of the garbage collector.
518
519 The behavior of the GC of the executables produced by nitc can be tuned with this environment variable.
520
521 The environment variable is used when programs are executed, not when they are compiled.
522 Thus, you do not need to recompile programs in order to tweak their GC options.
523
524 Available values are:
525
526 * boehm: use the Boehm-Demers-Weiser's conservative garbage collector (default).
527 * malloc: disable the GC and just use `malloc` without doing any `free`.
528 * large: disable the GC and just allocate a large memory area to use for all instantiation.
529 * help: show the list of available options.
530
531 ### `NIT_NO_STACK`
532 Runtime control of stack traces.
533
534 By default, stack traces are printed when a runtime errors occurs during the execution of a compiled program.
535 When setting this environment variable to a non empty value, such stack traces are disabled.
536
537 The environment variable is used when programs are executed, not when they are compiled.
538 Thus, you do not need to recompile programs in order to disable generated stack traces.
539
540 Note that stack traces require that, during the compilation, development files of the library `libunwind` are available.
541 If they are not available, then programs are compiled without any stack trace support.
542
543 To completely disable stack traces, see the option `--no-stacktrace`.
544
545 # SEE ALSO
546
547 The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>