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