···1717 `git status`)
181819192. Configure your source tree by running:
2020-2121- ./configure
2020++
2121+[source,sh]
2222+----
2323+./configure
2424+----
222523263. Bring your system to a stable state. Concretely, this means that the
2427 boot/ directory should contain a version of ocamlrun and all the
2528 \*.cm* files of the standard library. This stable state can be reached
2629 by running
2727-2828- make world
3030++
3131+[source,sh]
3232+----
3333+make world
3434+----
2935+
3036(Actually, running `make coldstart` should be enough but `make world` is
3137safer. Similarly, `make world.opt` will also bring you to such a stable
···3743 represented or anything else in the format of .cmi files, etc.
384439455. Run:
4040-4141- make coreall
4646++
4747+[source,sh]
4848+----
4949+make coreall
5050+----
4251+
4352This will rebuild runtime/ocamlrun, ocamlc, etc.
445345546. (optional) The new system can now be tested:
4646-4747- echo 'let _ = print_string "Hello world!\n"' > foo.ml
4848- ./boot/ocamlrun ./ocamlc -I ./stdlib foo.ml
4949- ./runtime/ocamlrun a.out
5555++
5656+[source,sh]
5757+----
5858+echo 'let _ = print_string "Hello world!\n"' > foo.ml
5959+./boot/ocamlrun ./ocamlc -I ./stdlib foo.ml
6060+./runtime/ocamlrun a.out
6161+----
506251637. We now know the system works and can thus build the new boot/
5264 binaries:
6565++
6666+[source,sh]
6767+----
6868+make bootstrap
6969+----
53705454- make bootstrap
5555-5656-= Problems
7171+== Problems
57725873If you notice that this procedure fails for a given change you are
5974trying to implement, please report it so that the procedure can be
6075updated to also cope with your change.
61766262-= Upstreaming
7777+== Upstreaming
63786479If you want to upstream your changes, indicate in the message of the
6580commit that the changes need a bootstrap. Perform the bootstrap and
6681commit the result of the bootstrap separately, after that commit.
67826868-= Adding, removing and renaming primitives
8383+== Adding, removing and renaming primitives
69847085Primitives can be added without having to bootstrap, however it is necessary
7186to repeat `make coldstart` in order to use your new primitive in the standard
···779278932. Create a temporary stub with the old primitive's name. This stub simply
7994 passes its arguments on to the new primitive:
8080-8181- CAMLprim value caml_old_primitive(value a1, value a2) {
8282- return caml_new_primitive(a1, a2);
8383- }
9595++
9696+[source,c]
9797+----
9898+CAMLprim value caml_old_primitive(value a1, value a2) {
9999+ return caml_new_primitive(a1, a2);
100100+}
101101+----
84102851033. Deal with the addition of the new primitive:
8686-8787- make coldstart
104104++
105105+[source,sh]
106106+----
107107+make coldstart
108108+----
88109891104. Ensure the system still works:
9090-9191- make coreall
111111++
112112+[source,sh]
113113+----
114114+make coreall
115115+----
92116931175. Now remove the old primitive stub and issue:
9494-9595- make bootstrap
118118++
119119+[source,sh]
120120+----
121121+make bootstrap
122122+----
9612397124It is desirable for bootstraps to be easily repeatable, so you should commit
98125changes after step 4.
···1021291. Start with a working build of the compiler eg `./configure && make world`
1031301041312. Remove uses of the primitive, but not the primitive itself. Then ensure the system still works:
105105-106106- make coreall
132132++
133133+[source,sh]
134134+----
135135+make coreall
136136+----
1071371081383. Then, and only then, remove the primitive, and run:
139139++
140140+[source,sh]
141141+----
142142+make coreall
143143+make bootstrap
144144+----
109145110110- make coreall
111111- make bootstrap
112112-113113-= Bootstrap test script
146146+== Bootstrap test script
114147115148A script is provided (and used on Inria's continuous
116149integration infrastructure) to make sure the bootstrap works. This
···119152a primitive from the runtime. It then makes sure the bootstrap still
120153works after these changes. This script can be run locally as follows:
121154122122- OCAML_ARCH=linux ./tools/ci/inria/bootstrap
155155+[source,sh]
156156+----
157157+OCAML_ARCH=linux ./tools/ci/inria/bootstrap
158158+----
+1-1
CONTRIBUTING.md
···11# How to contribute changes
2233-:+1::tada: First off, thank you for taking time to contribute! :tada::+1:
33+👍🎉 First off, thank you for taking time to contribute! 👍🎉
4455The following is a set of guidelines for proposing changes to the
66OCaml distribution. These are just guidelines, not rules, use your
+3
Changes
···304304 `Thread.join` on the domain's systhreads.
305305 (Raphaël Proust, review by Gabriel Scherer)
306306307307+- #14392: Fix AsciiDoc files, add more markup, xrefs, documentation.
308308+ (Antonin Décimo, review by Gabriel Scherer and David Allsopp)
309309+307310### Compiler user-interface and warnings:
308311309312- #12628: Improved error message for unsafe values: print out the full path for
+97-79
HACKING.adoc
···11-= Hacking the compiler :camel:
11+= Hacking the compiler 🐫
2233This document is a work-in-progress attempt to provide useful
44information for people willing to inspect or modify the compiler
···88If you already have a patch that you would like to contribute to the
99official distribution, please see link:CONTRIBUTING.md[].
10101111-=== Your first compiler modification
1111+== Your first compiler modification
121213131. Create a new git branch to store your changes.
1414+
1515+[source,sh]
1516----
1617git checkout -b my-modification
1718----
···2324not have this which causes some important development things to be disabled
2425(ocamltest and converting C compiler warnings to errors).
25262626-2. Consult link:INSTALL.adoc[] for build instructions. Here is the gist of it:
2727+2. Consult xref:INSTALL.adoc[] for build instructions. Here is the gist of it:
2728+
2929+[source,sh]
2830----
2931./configure
3032make -j 4
···36383. Try the newly built compiler binaries `ocamlc`, `ocamlopt` or their
3739`.opt` version. To try the toplevel, use:
3840+
4141+[source,sh]
3942----
4043make runtop
4144----
···444745485. Run the testsuite from time to time.
4649+
5050+[source,sh]
4751----
4852make tests
4953----
···5357See also our <<tips,development tips and tricks>>, for example on how to
5458<<opam-switch,create an opam switch>> to test your modified compiler.
55595656-=== What to do
6060+== What to do
57615862There is always a lot of potential tasks, both for old and
5963newcomers. Here are various potential projects:
···7680 clarifying comments can be an excellent contribution to help you,
7781 next time, and other code readers.
78827979-* The https://github.com/ocaml/ocaml[github project] contains a lot of
8383+* The https://github.com/ocaml/ocaml[GitHub project] contains a lot of
8084 pull requests, many of them being in dire need of a review -- we
8185 have more people willing to contribute changes than to review
8286 someone else's change. Picking one of them, trying to understand the
···109113110114Parses source files and produces an Abstract Syntax Tree (AST)
111115(link:parsing/parsetree.mli[] has lot of helpful comments). See
112112-link:parsing/HACKING.adoc[].
116116+xref:parsing/HACKING.adoc[].
113117114118The logic for Camlp4 and Ppx preprocessing is not in link:parsing/[],
115119but in link:driver/[], see link:driver/pparse.mli[] and
···119123120124Type-checks the AST and produces a typed representation of the program
121125(link:typing/typedtree.mli[] has some helpful comments). See
122122-link:typing/HACKING.adoc[].
126126+xref:typing/HACKING.adoc[].
123127124128==== The bytecode compiler -- link:bytecomp/[]
125129···141145and `runtime_NATIVE_ONLY_C_SOURCES` in link:Makefile[] for the list of common,
142146bytecode-only, and native-only source files.)
143147144144-See link:runtime/HACKING.adoc[].
148148+See xref:runtime/HACKING.adoc[].
145149146150=== Libraries
147151···156160comments in `.mli` files in the compiler codebase, you can observe the
157161result by running
158162163163+[source,sh]
159164----
160165make html_doc
161166----
···172177link:yacc/[]:: The `ocamlyacc` parser generator. We do not recommend
173178using it for user projects in need of a parser generator. Please
174179consider using and contributing to
175175-link:http://gallium.inria.fr/~fpottier/menhir/[menhir] instead, which
180180+link:https://gallium.inria.fr/~fpottier/menhir/[menhir] instead, which
176181has tons of extra features, lets you write more readable grammars, and
177182has excellent documentation.
178183179184=== Complete file listing
180185181181- BOOTSTRAP.adoc:: instructions for bootstrapping
182182- Changes:: what's new with each release
183183- CONTRIBUTING.md:: how to contribute to OCaml
184184- HACKING.adoc:: this file
185185- INSTALL.adoc:: instructions for installation
186186- LICENSE:: license and copyright notice
187187- Makefile:: main Makefile
188188- Makefile.common:: common Makefile definitions
189189- README.adoc:: general information on the compiler distribution
190190- README.win32.adoc:: general information on the Windows ports of OCaml
191191- VERSION:: version string. Run `tools/autogen` after changing.
192192- asmcomp/:: native-code compiler and linker
193193- boot/:: bootstrap compiler
194194- build-aux/:: autotools support scripts
195195- bytecomp/:: bytecode compiler and linker
196196- compilerlibs/:: the OCaml compiler as a library
197197- configure:: configure script
198198- configure.ac:: autoconf input file
199199- debugger/:: source-level replay debugger
200200- driver/:: driver code for the compilers
201201- flexdll/:: git submodule -- see link:README.win32.adoc[]
202202- lex/:: lexer generator
203203- man/:: man pages
204204- manual/:: system to generate the manual
205205- middle_end/:: the flambda optimisation phase
206206- ocamldoc/:: documentation generator
207207- ocamltest/:: test driver
208208- otherlibs/:: several additional libraries
209209- parsing/:: syntax analysis -- see link:parsing/HACKING.adoc[]
210210- release-info/:: documentation and tools to prepare releases
211211- runtime/:: bytecode interpreter and runtime systems
212212- stdlib/:: standard library
213213- testsuite/:: tests -- see link:testsuite/HACKING.adoc[]
214214- tools/:: various utilities
215215- toplevel/:: interactive system
216216- typing/:: typechecking -- see link:typing/HACKING.adoc[]
217217- utils/:: utility libraries
218218- winpthreads/:: winpthreads submodule -- see <<winpthreads,further>>
219219- yacc/:: parser generator
186186+ xref:BOOTSTRAP.adoc[]:: instructions for bootstrapping
187187+ link:Changes[]:: what’s new with each release
188188+ link:CONTRIBUTING.md[]:: how to contribute to OCaml
189189+ xref:HACKING.adoc[]:: this file
190190+ xref:INSTALL.adoc[]:: instructions for installation
191191+ link:LICENSE[]:: license and copyright notice
192192+ link:Makefile[]:: main Makefile
193193+ link:Makefile.common[]:: common Makefile definitions
194194+ xref:README.adoc[]:: general information on the compiler distribution
195195+ xref:README.win32.adoc[]:: general information on the Windows ports of OCaml
196196+ link:VERSION[]:: version string. Run `make configure` after changing.
197197+ link:asmcomp/[]:: native-code compiler and linker
198198+ link:boot/[]:: bootstrap compiler
199199+ link:build-aux/[]:: autotools support scripts
200200+ link:bytecomp/[]:: bytecode compiler and linker
201201+ link:compilerlibs/[]:: the OCaml compiler as a library
202202+ link:configure[]:: configure script
203203+ link:configure.ac[]:: autoconf input file
204204+ link:debugger/[]:: source-level replay debugger
205205+ link:driver/[]:: driver code for the compilers
206206+ link:flexdll/[]:: git submodule -- see xref:README.win32.adoc[]
207207+ link:lex/[]:: lexer generator
208208+ link:man/[]:: man pages
209209+ link:manual/[]:: system to generate the manual
210210+ link:middle_end/[]:: the flambda optimisation phase
211211+ link:ocamldoc/[]:: documentation generator
212212+ link:ocamltest/[]:: test driver
213213+ link:otherlibs/[]:: several additional libraries
214214+ link:parsing/[]:: syntax analysis -- see xref:parsing/HACKING.adoc[]
215215+ link:release-info/[]:: documentation and tools to prepare releases
216216+ link:runtime/[]:: bytecode interpreter and runtime systems
217217+ link:stdlib/[]:: standard library
218218+ link:testsuite/[]:: tests -- see xref:testsuite/HACKING.adoc[]
219219+ link:tools/[]:: various utilities
220220+ link:toplevel/[]:: interactive system
221221+ link:typing/[]:: typechecking -- see xref:typing/HACKING.adoc[]
222222+ link:utils/[]:: utility libraries
223223+ link:winpthreads/[]:: winpthreads submodule -- see <<winpthreads,further>>
224224+ link:yacc/[]:: parser generator
220225221226[#tips]
222227== Development tips and tricks
223228224224-=== Keep merge commits when merging and cherry-picking Github PRs
229229+=== Keep merge commits when merging and cherry-picking GitHub PRs
225230226226-Having the Github PR number show up in the git log is very useful for
231231+Having the GitHub PR number show up in the git log is very useful for
227232later triaging. We recently disabled the "Rebase and merge" button,
228233precisely because it does not produce a merge commit.
229234···233238option.) You should also use the `-x` option to include the hash of
234239the original commit in the commit message.
235240241241+[source,sh]
236242----
237243git cherry-pick -x -m 1 <merge-commit-hash>
238244----
···248254https://editorconfig.org/#download[plugins].
249255250256[#opam-switch]
251251-=== Testing with `opam`
257257+=== Testing with opam
252258253259If you are working on a development version of the compiler, you can create an
254260opam switch from it by running the following from the development repository:
255261262262+[source,sh]
256263-----
257264opam switch create . --empty
258265opam install .
···262269git repository, you can build a switch directly (without cloning their
263270work locally) by pinning:
264271272272+[source,sh]
265273----
266274opam switch create my-switch-name --empty
267267-opam pin add ocaml-variants git+https://$REPO#branch
275275+opam pin add ocaml-variants "git+https://$REPO#branch"
268276----
269277270270-==== Incremental builds with `opam`
278278+==== Incremental builds with opam
271279272280This section documents some tips to speed up your workflow when you need to
273281alternate between testing your branch and patching the compiler.
···276284===== Initial setup
277285278286For the rest of the section to work, you'll need your compiler to be
279279-configured in the same way as `opam` would have configured it. The simplest
287287+configured in the same way as opam would have configured it. The simplest
280288way is to run the normal commands for the switch initialization, with the extra
281289`--inplace-build` flag:
282290291291+[source,sh]
283292-----
284293opam switch create . --empty
285294opam install . --inplace-build
···287296288297However, if you need specific configuration options, you can also configure it
289298manually, as long as you make sure that the configuration prefix is the one
290290-where `opam` would install the compiler.
299299+where opam would install the compiler.
291300You will then need to install the compiler, either from the working directory
292301(that you must build yourself) or using the regular sandboxed builds.
293302303303+[source,sh]
294304-----
295305# Example with regular opam build
296306opam switch create . --empty
···298308./configure --prefix=$(opam var prefix) # put extra configuration args here
299309-----
300310311311+[source,sh]
301312-----
302313# Example with installation from the current directory
303314opam switch create . --empty
···309320===== Basic workflow
310321311322We will assume that the workflow alternates between work on the compiler and
312312-external (`opam`-related) commands.
323323+external (opam-related) commands.
313324As an example, debugging an issue in the compiler can be done by a first step
314314-that triggers the issue (by installing a given `opam` package), then adding
325325+that triggers the issue (by installing a given opam package), then adding
315326some logging to the compiler, re-trigger the issue, and based on the logs either
316327add more logging, or try a patch, and so on.
317328···328339329340In our case, we need to build the compiler, and when we've built everything
330341that we need then we run `opam custom-install ocaml-variants -- make install`.
331331-This will make `opam` remove the previously installed version of the compiler
342342+This will make opam remove the previously installed version of the compiler
332343(if any), then install the new one in its stead.
333344345345+[source,sh]
334346-----
335347# reinstall the compiler, and rebuild all opam packages
336348opam custom-install ocaml-variants -- make install
337349-----
338350339339-Since most `opam` packages depend on the compiler, this will trigger a
351351+Since most opam packages depend on the compiler, this will trigger a
340352reinstallation of all the packages in the switch.
341353If you want to avoid that (for instance, your patch only adds some logging
342354so you expect the core libraries and all the already compiled packages to be
···345357changing even slightly one of the core libraries' files, you will likely
346358get inconsistent assumptions errors later.
347359360360+[source,sh]
348361-----
349362# reinstall the compiler, leaving the opam packages untouched -- unsafe!
350363opam custom-install --no-recompilations ocaml-variants -- make install
···352365353366Note about the first installation:
354367When you start from an empty switch, and install a compiler (in our case,
355355-the `ocaml-variants` package provided by the compiler's `opam` file), then
368368+the `ocaml-variants` package provided by the compiler's opam file), then
356369a number of additional packages are installed to ensure that the switch
357370will work correctly. Mainly, the `ocaml` package needs to be installed,
358358-and while it's done automatically when using regular `opam` commands, the
371371+and while it's done automatically when using regular opam commands, the
359372`custom-install` plugin will not force installation of dependencies.
360373Moreover, if you try to fix the problem by manually installing the `ocaml`
361361-package, `opam` will try to recompile `ocaml-variants`, using the default
374374+package, opam will try to recompile `ocaml-variants`, using the default
362375instructions. You can get around this by running
363376`opam reinstall --forget-pending` just after the `opam custom-install` command
364377and just before the `opam install ocaml command`.
365378Full example:
366379380380+[source,sh]
367381-----
368382opam switch create . --empty
369383./configure --prefix=$(opam var prefix) --disable-ocamldoc --disable-ocamltest
···381395bytecode tools are installed, whereas with a raw `make install` you will have
382396stale native binaries remaining in your switch.
383397Since it's significantly faster to build the bytecode version of the tools,
384384-and many `opam` packages will pick the native version of the compilers if
398398+and many opam packages will pick the native version of the compilers if
385399present and the bytecode version otherwise, you can build your initial switch
386400with the native versions (to get quickly to a state where a bug appears),
387401then clean your working directory and start building bytecode tools only
···389403390404===== Without `opam-custom-install`
391405392392-You can achieve some improvements using built-in `opam` commands.
406406+You can achieve some improvements using built-in opam commands.
393407394408Using `opam install . --assume-built` will simply remove the
395409package for the compiler, then run the installation instructions
···400414401415You can also run `make install` manually, which will not trigger a
402416recompilation, but will not remove the previous version either and can
403403-mess with `opam`'s tracking of installed files.
417417+mess with opam's tracking of installed files.
404418405419=== Useful Makefile targets and options
406420407407-Besides the targets listed in link:INSTALL.adoc[] for build and
421421+Besides the targets listed in xref:INSTALL.adoc[] for build and
408422installation, the following targets may be of use:
409423410424`make runtop` :: builds and runs the ocaml toplevel of the distribution
···417431418432`make depend`:: Regenerate the `.depend` file. Should be used each time new dependencies are added between files.
419433420420-`make -C testsuite parallel`:: see link:testsuite/HACKING.adoc[]
434434+`make -C testsuite parallel`:: see xref:testsuite/HACKING.adoc[]
421435422436You can use `make foo V=1` to build the target foo and show full
423423-commands instead of abbreviated names like OCAMLC, etc. This can be
437437+commands instead of abbreviated names like `OCAMLC`, etc. This can be
424438useful to know the flags to use to manually rebuild a file.
425439426440Additionally, there are some developer specific targets in link:Makefile.dev[].
···468482link:boot/[] directory. These bytecode images are used once the
469483bytecode runtime (which is written in C) has been built to compile the
470484standard library and then to build a fresh compiler. Details can be
471471-found in link:BOOTSTRAP.adoc[].
485485+found in xref:BOOTSTRAP.adoc[].
472486473487=== Speeding up builds
474488475489Once you've built a natively-compiled `ocamlc.opt`, you can use it to
476490speed up future builds by copying it to `boot`:
477491492492+[source,sh]
478493----
479494cp ocamlc.opt boot/
480495----
···498513version installed with merlin and dune, you can just run the following from the
499514compiler sources:
500515516516+[source,sh]
501517----
502518./configure # if not already done
503519make clean-for-dune && dune build @libs
···604620If you're using a version of GNU Autoconf that differs from our CI,
605621then the generated `configure` script might differ too. The latest
606622Ubuntu LTS packages may be used as a reasonable base to generate this
607607-file. Using a Docker image with GNU Autoconf installed, and `git
608608-rebase --exec`, one can properly regenerate the `configure` script for
609609-each commit in a branch.
623623+file. Using a Docker image with GNU Autoconf installed, and
624624+`git rebase --exec`, one can properly regenerate the `configure`
625625+script for each commit in a branch.
610626611627[source,sh]
612628----
···632648machine, you can use the configuration values and run command taken from
633649link:tools/ci/actions/runner.sh[]:
634650651651+[source,sh]
635652----
636653bash -ex tools/ci/actions/runner.sh configure
637654----
···642659set explicitly to reproduce them locally.
643660644661`Changes updated` checks that the link:Changes[] file has been modified
645645-(hopefully to add a new entry). It can be disabled by including "_(no change
646646-entry needed)_" in one of your commit messages -- but in general all patches
647647-submitted should come with a Changes entry; see the guidelines in
648648-link:CONTRIBUTING.md[].
662662+(hopefully to add a new entry). In general all patches submitted should come
663663+with a Changes entry; see the guidelines in link:CONTRIBUTING.md[].
649664650665The Windows ports take a long time to test - INRIA's precheck service is the
651666best to use when all 6 Windows ports need testing for a branch, but the
···693708INRIA provides a Jenkins continuous integration service that OCaml
694709uses, see link:https://ci.inria.fr/ocaml/[]. It provides a wider
695710architecture support (MSVC and MinGW, a zsystems s390x machine, and
696696-various MacOS versions) than the Travis/AppVeyor testing on github,
711711+various MacOS versions) than the Travis/AppVeyor testing on GitHub,
697712but only runs on commits to the trunk or release branches, not on every
698713PR.
699714···711726712727If you have suspicions that your changes may fail on exotic architectures
713728(they touch the build system or the backend code generator,
714714-for example) and would like to get wider testing than github's CI
729729+for example) and would like to get wider testing than GitHub's CI
715730provides, it is possible to manually start INRIA's CI on arbitrary git
716731branches even before opening a pull request as follows:
717732···7297445. Visit https://ci.inria.fr/ocaml/job/precheck and log in. Click on
730745"Build with parameters".
731746732732-6. Fill in the REPO_URL and BRANCH fields as appropriate and run the build.
747747+6. Fill in the `REPO_URL` and `BRANCH` fields as appropriate and run the build.
7337487347497. You should receive a bunch of e-mails with the build logs for each
735750slave and each tested configuration (with and without flambda) attached.
···745760branch. In order to use "precheck" to test parallel build on a custom
746761branch, add this at the beginning of tools/ci-build:
747762763763+[source,sh]
748764----
749765OCAML_JOBS=10
750766----
···765781766782To recreate the `winpthreads` repository from upstream, you can do:
767783784784+[source,sh]
768785----
769786git clone -o upstream https://git.code.sf.net/p/mingw-w64/mingw-w64 winpthreads
770787cd winpthreads
···776793As subtree splitting is deterministic, repeating these operations later will
777794allow to update `master`, for instance by:
778795796796+[source,sh]
779797----
780798git fetch upstream
781799git checkout upstream/master
+83-44
INSTALL.adoc
···77 ** For GNU/Linux +
88 The GNU C Compiler (`gcc`) is recommended as the bytecode interpreter takes
99 advantage of GCC-specific features to enhance performance. GCC is the standard
1010- compiler under Linux and many other systems.
1010+ compiler under Linux and many other systems. Clang (`clang`) should also be a
1111+ safe choice.
11121213 ** For BSDs +
1313- `clang` is the default C compiler on BSDs - also works fine.
1414+ Clang (`clang`) is the default C compiler on BSDs - also works fine.
14151516 ** For macOS +
1616- `clang` is the default C compiler under macOS. If macOS complains
1717- no C compiler was installed while OCaml is building, please run
1818- command `xcode-select --install` to install command-line tools and
1919- required libraries and header files.
1717+ Apple Clang (`clang`) is the default C compiler under macOS. If macOS
1818+ complains that no C compiler is installed while OCaml is building, run
1919+ command `xcode-select --install` to install command-line tools, required
2020+ libraries, and header files.
20212122 ** For other Unix-like systems +
2223 It is recommended to use `gcc` or `clang` instead of the C compiler
···2526 ** For Windows +
2627 To produce native Windows executables from OCaml sources, you need to use
2728 the MSVC or MinGW-w64 ports of OCaml, described in file
2828- https://github.com/ocaml/ocaml/blob/trunk/README.win32.adoc[README.win32.adoc]. +
2929- For a more Unix-like experience, you can use WSL, the
3030- https://aka.ms/wsl[Windows Subsystem for Linux], or the
3131- https://www.cygwin.com/[Cygwin environment]. You will need the
2929+ xref:README.win32.adoc[]. +
3030+ For a more Unix-like experience, you can use the
3131+ https://aka.ms/wsl[Windows Subsystem for Linux] (WSL), or the
3232+ https://www.cygwin.com/[Cygwin environment]. With Cygwin, you will need the
3233 GCC compiler (package `gcc-core` or `gcc`).
33343434-* GNU `make`, as well as POSIX-compatible `awk` and `sed` are required.
3535+* GNU Make (`make` or `gmake`), as well as POSIX-compatible `awk` and `sed` are
3636+ required.
35373638* A POSIX-compatible `diff` is necessary to run the test suite.
3739···53555456From the top directory, do:
55575656- ./configure
5858+[source,sh]
5959+----
6060+./configure
6161+----
57625863This generates the three configuration files `Makefile.config`,
5964`runtime/caml/m.h` and `runtime/caml/s.h`.
60656166The `configure` script accepts options that can be discovered by running:
62676363- ./configure --help
6868+[source,sh]
6969+----
7070+./configure --help
7171+----
64726565-Some options or variables like LDLIBS may not be taken into account
7373+Some options or variables like `LDLIBS` may not be taken into account
6674by the OCaml build system at the moment. Please report an issue if you
6775discover such a variable or option and this causes troubles to you.
68766977Examples:
70787179* Standard installation in `/usr/{bin,lib,man}` instead of `/usr/local`:
7272- ./configure --prefix=/usr
7373-8080++
8181+[source,sh]
8282+----
8383+./configure --prefix=/usr
8484+----
74857586* On a Linux x86-64 host, to build a 32-bit version of OCaml:
7676-7777- ./configure --build=x86_64-pc-linux-gnu --host=i686-linux-gnu
8787++
8888+[source,sh]
8989+----
9090+./configure --build=x86_64-pc-linux-gnu --host=i686-linux-gnu
9191+----
78927993* For AIX 7.x with the IBM compiler `xlc`:
8080-8181- ./configure CC=xlc
8294+
8383-By default, build is 32-bit. For 64-bit build, please set environment variable `OBJECT_MODE=64`
9595+[source,sh]
9696+----
9797+./configure CC=xlc
9898+----
9999++
100100+By default, the build is 32-bit. For the 64-bit build, set the environment variable `OBJECT_MODE=64`
84101 for _both_ `configure` and `make world` phases. Note, if this variable is set for only one phase,
85102 your build will break (`ocamlrun` segfaults).
8686-+
103103+87104* For Solaris/Illumos on SPARC machines with Sun PRO compiler only 64-bit
88105 bytecode target is supported (32-bit fails due to alignment issues; the optimization
89106 is preset to `-O4` for inlining):
107107++
108108+[source,sh]
109109+----
110110+./configure CC="cc -m64"
111111+----
901129191- ./configure CC="cc -m64"
9292-+
93113If something goes wrong during the automatic configuration, or if the generated
94114files cause errors later on, then look at the template files:
951159696- Makefile.config.in
9797- Makefile.build_config.in
9898- runtime/caml/m.h.in
9999- runtime/caml/s.h.in
100100-+
116116+----
117117+Makefile.config.in
118118+Makefile.build_config.in
119119+runtime/caml/m.h.in
120120+runtime/caml/s.h.in
121121+----
122122+101123for guidance on how to edit the generated files by hand.
102124103125== Building the compiler
104126105127From the top directory, do:
106106-107107- make
128128+[source,sh]
129129+----
130130+make
131131+----
108132109133This builds the OCaml compiler for the first time. This phase is
110134fairly verbose; consider redirecting the output to a file:
111135112112- make > make.log 2>&1 # in sh
113113- make >& make.log # in csh
136136+[source,sh]
137137+----
138138+make > make.log 2>&1 # in sh
139139+make >& make.log # in csh
140140+----
114141115142== (Optional) Running the testsuite
116143117144To be sure everything works well, you can run the test suite
118145 that comes with the compiler. To do so, do:
119146120120- make tests
147147+[source,sh]
148148+----
149149+make tests
150150+----
121151122152== Installing the compiler
123153···143173144174From the top directory, become superuser and do:
145175146146- make install
176176+[source,sh]
177177+----
178178+make install
179179+----
147180148181Installation is complete. Time to clean up. From the toplevel directory,
149182 do:
150183151151- make clean
184184+[source,sh]
185185+----
186186+make clean
187187+----
152188153189After installation, do *not* strip the `ocamldebug` executables.
154190 This is a mixed-mode executable (containing both compiled C
···161197this file.
162198163199Check the files `m.h` and `s.h` in `runtime/caml/`.
164164-Wrong endianness or alignment constraints in `machine.h` will
200200+Wrong endianness or alignment constraints in `m.h` will
165201immediately crash the bytecode interpreter.
166202167203If you get a "segmentation violation" signal, check the limits on the stack size
···205241generates code for a different machine, named the _target_. To build a cross
206242compiler you first need to have a non-cross compiler of the same version
207243installed in your `$PATH`. You can install that standard non-cross compiler by
208208-any means, for instance using `opam` or compiling it manually from source. Note
244244+any means, for instance using opam or compiling it manually from source. Note
209245though that the version of the non-cross compiler must match the version of the
210246cross compiler since the cross compiler will be compiled by the non-cross
211247compiler: the cross compiler will combine code compiled from source with the
···217253setting the `TARGET_LIBDIR` variable. For instance, with the GCC MinGW cross
218254compiler installed, one may use:
219255220220-....
256256+[source,sh]
257257+----
221258./configure --prefix=$PWD/cross --target=x86_64-w64-mingw32 TARGET_LIBDIR='C:\somedir' ...
222259make crossopt -j
223260make installcross
224224-....
261261+----
225262226263Notes:
227264···239276If you have built a cross compiler to a Unix target, you can simply run as
240277usual:
241278242242-....
279279+[source,sh]
280280+----
243281cross/bin/ocamlopt.opt -o test test.ml
244244-....
282282+----
245283246284If you have built a Unix-to-Windows cross compiler, you must first make sure
247285that `ocamlopt` can find the `flexlink` executable in `$PATH` when it needs to
248286link. Bootstrapping `flexdll` builds a `flexlink.exe` (note the `.exe`!), so you
249287can:
250288251251-....
289289+[source,sh]
290290+----
252291ln -s flexlink.exe cross/bin/flexlink
253292(export PATH="$PWD/cross/bin:$PATH"; ocamlopt.opt.exe -o test.exe test.ml)
254254-....
293293+----
255294256295or any other possibility to make sure `ocamlopt` can invoke `flexlink`.
+14-14
README.adoc
···11+= README
22+13[CAUTION]
24====
35The developer team released OCaml 5.0.0 in December 2022. OCaml 5.x features a
···1416|=====
1517| Branch `trunk` | Branch `5.4` | Branch `5.3` | Branch `5.2` | Branch `4.14`
16181717-| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=trunk["Github CI Build Status (trunk branch)",
1919+| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=trunk["GitHub CI Build Status (trunk branch)",
1820 link="https://github.com/ocaml/ocaml/actions?query=workflow%3ABuild"]
1919- image:https://github.com/ocaml/ocaml/workflows/Hygiene/badge.svg?branch=trunk["Github CI Hygiene Status (trunk branch)",
2121+ image:https://github.com/ocaml/ocaml/workflows/Hygiene/badge.svg?branch=trunk["GitHub CI Hygiene Status (trunk branch)",
2022 link="https://github.com/ocaml/ocaml/actions?query=workflow%3AHygiene"]
2123 image:https://ci.appveyor.com/api/projects/status/github/ocaml/ocaml?branch=trunk&svg=true["AppVeyor Build Status (trunk branch)",
2224 link="https://ci.appveyor.com/project/avsm/ocaml"]
2323-| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=5.4["Github CI Build Status (5.4 branch)",
2525+| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=5.4["GitHub CI Build Status (5.4 branch)",
2426 link="https://github.com/ocaml/ocaml/actions?query=workflow%3ABuild"]
2527 image:https://ci.appveyor.com/api/projects/status/github/ocaml/ocaml?branch=5.4&svg=true["AppVeyor Build Status (5.4 branch)",
2628 link="https://ci.appveyor.com/project/avsm/ocaml"]
2727-| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=5.3["Github CI Build Status (5.3 branch)",
2929+| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=5.3["GitHub CI Build Status (5.3 branch)",
2830 link="https://github.com/ocaml/ocaml/actions?query=workflow%3ABuild"]
2931 image:https://ci.appveyor.com/api/projects/status/github/ocaml/ocaml?branch=5.3&svg=true["AppVeyor Build Status (5.3 branch)",
3032 link="https://ci.appveyor.com/project/avsm/ocaml"]
3131-| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=5.2["Github CI Build Status (5.2 branch)",
3333+| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=5.2["GitHub CI Build Status (5.2 branch)",
3234 link="https://github.com/ocaml/ocaml/actions?query=workflow%3ABuild"]
3335 image:https://ci.appveyor.com/api/projects/status/github/ocaml/ocaml?branch=5.2&svg=true["AppVeyor Build Status (5.2 branch)",
3436 link="https://ci.appveyor.com/project/avsm/ocaml"]
3535-| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=4.14["Github CI Build Status (4.14 branch)",
3737+| image:https://github.com/ocaml/ocaml/workflows/Build/badge.svg?branch=4.14["GitHub CI Build Status (4.14 branch)",
3638 link="https://github.com/ocaml/ocaml/actions?query=workflow%3ABuild"]
3739 image:https://ci.appveyor.com/api/projects/status/github/ocaml/ocaml?branch=4.14&svg=true["AppVeyor Build Status (4.14 branch)",
3840 link="https://ci.appveyor.com/project/avsm/ocaml"]
3941|=====
40424141-= README =
4242-4343== Overview
44444545OCaml is a functional, statically-typed programming language from the
···86868787== Installation
88888989-See the file link:INSTALL.adoc[] for installation instructions on
8989+See the file xref:INSTALL.adoc[] for installation instructions on
9090machines running Unix, Linux, macOS, WSL and Cygwin. For native Microsoft
9191-Windows, see link:README.win32.adoc[].
9191+Windows, see xref:README.win32.adoc[].
92929393== Documentation
9494···146146147147== Contributing
148148149149-For information on contributing to OCaml, see link:HACKING.adoc[] and
149149+For information on contributing to OCaml, see xref:HACKING.adoc[] and
150150link:CONTRIBUTING.md[].
151151152152== Separately maintained components
153153154154Some libraries and tools which used to be part of the OCaml distribution are
155155-now maintained separately and distributed as OPAM packages.
155155+now maintained separately and distributed as opam packages.
156156Please use the issue trackers at their respective new homes:
157157158158|====
159159-| Library | Removed since | OPAM package
159159+| Library | Removed since | opam package
160160161161| https://github.com/ocaml/camlp-streams/issues[The Stream and Genlex standard library modules] | OCaml 5.0 | `camlp-streams`
162162| https://github.com/ocaml/graphics/issues[The Graphics library] | OCaml 4.09 | `graphics`
···166166| https://github.com/garrigue/labltk/issues[The LablTk library] | OCaml 4.02 | `labltk`
167167| https://github.com/ocaml/dbm/issues[The CamlDBM library] | OCaml 4.00 | `dbm`
168168| https://github.com/xavierleroy/ocamltopwin/issues[The OCamlWinTop Windows toplevel] | OCaml 4.00 | none
169169-|=====
169169+|====
+64-26
README.win32.adoc
···43434444Cygwin aims to provide a Unix-like environment on Windows, and the build
4545procedure for it is the same as for other flavours of Unix. See
4646-link:INSTALL.adoc[] for full instructions.
4646+xref:INSTALL.adoc[] for full instructions.
47474848OCaml requires Windows 8 or later and naturally the 64-bit versions need a
494964-bit edition of Windows (note that this is both to run *and* build).
···118118Once you have started a Command Prompt, you can verify that you have the
119119compiler you are expecting simply by running:
120120121121- cl
122122- Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33133 for x64
123123- ...
121121+[source,console]
122122+----
123123+> cl
124124+Microsoft (R) C/C++ Optimizing Compiler Version 19.38.33133 for x64
125125+...
126126+----
124127125128You then need to start Cygwin from this Command Prompt. Assuming you have
126129installed it to its default location of `C:\cygwin64`, simply run:
127130128128- C:\cygwin64\bin\mintty -
131131+[source,bat]
132132+----
133133+C:\cygwin64\bin\mintty -
134134+----
129135130136(note the space and hyphen at the end of the command).
131137···139145the beginning of `PATH`, before Cygwin's `/usr/bin`. You can automate this from
140146the top-level of the OCaml distribution by running:
141147142142- eval $(tools/msvs-promote-path)
148148+[source,sh]
149149+----
150150+eval $(tools/msvs-promote-path)
151151+----
143152144153If you forget to do this, `make` will fail relatively
145154quickly as it will be unable to link `ocamlrun`.
146155147156For 64-bit, now run:
148157149149- ./configure --build=x86_64-pc-cygwin --host=x86_64-pc-windows
158158+[source,sh]
159159+----
160160+./configure --build=x86_64-pc-cygwin --host=x86_64-pc-windows
161161+----
150162151163or, for 32-bit:
152164153153- ./configure --build=x86_64-pc-cygwin --host=i686-pc-windows
165165+[source,sh]
166166+----
167167+./configure --build=x86_64-pc-cygwin --host=i686-pc-windows
168168+----
154169155170If you wish to compile with Clang, add `CC=clang-cl`.
156171157172Finally, use `make` to build the system, e.g.
158173159159- make
160160- make install
174174+[source,sh]
175175+----
176176+make
177177+make install
178178+----
161179162180After installing, it is not necessary to keep the Cygwin installation (although
163181you may require it to build additional third party libraries and tools). You
···169187like to copy the `tools/msvs-promote-path` script and add the `eval` line to
170188your `~/.bashrc` file.
171189172172-* The Microsoft Visual C/C++ compiler does not implement "computed gotos", and
173173- therefore generates inefficient code for `runtime/interp.c`. Consequently,
174174- the performance of bytecode programs is about 2/3 of that obtained under
175175- Unix/GCC, Cygwin or MinGW-w64 on similar hardware.
190190+* The Microsoft Visual C/C++ compiler does not implement "computed gotos" (also
191191+ known as "labels as values"), and therefore generates inefficient code for the
192192+ bytecode interpreter in `runtime/interp.c`. Consequently, the performance of
193193+ bytecode programs is about 2/3 of that obtained under Unix/GCC, Cygwin or
194194+ MinGW-w64 on similar hardware. The clang-cl compiler supports the "computed
195195+ gotos" extension.
176196177177-* Libraries available in this port: `dynlink`, `num`,
178178- `str`, `threads`, and large parts of `unix`.
197197+* Libraries available in this port: `dynlink`, `str`, `threads`, and large parts
198198+ of `unix`.
179199180200* The replay debugger is partially supported (no reverse execution).
181201···211231212232For 64-bit, now run:
213233214214- ./configure --build=x86_64-pc-cygwin --host=x86_64-w64-mingw32
234234+[source,sh]
235235+----
236236+./configure --build=x86_64-pc-cygwin --host=x86_64-w64-mingw32
237237+----
215238216239or, for 32-bit:
217240218218- ./configure --build=x86_64-pc-cygwin --host=i686-w64-mingw32
241241+[source,sh]
242242+----
243243+./configure --build=x86_64-pc-cygwin --host=i686-w64-mingw32
244244+----
219245220246Finally, use `make` to build the system, e.g.
221247222222- make
223223- make install
248248+[source,sh]
249249+----
250250+make
251251+make install
252252+----
224253225254After installing, you will need to ensure that `ocamlopt` (or `ocamlc -custom`)
226255can access the C compiler. You can do this either by using OCaml from Cygwin's
227256bash or by adding Cygwin's bin directory (e.g. `C:\cygwin64\bin`) to your
228257`PATH`.
229258230230-* Libraries available in this port: `dynlink`, `num`,
231231- `str`, `threads`, and large parts of `unix`.
259259+* Libraries available in this port: `dynlink`, `str`, `threads`, and large parts
260260+ of `unix`.
232261233262* The replay debugger is partially supported (no reverse execution).
234263···249278 https://github.com/ocaml/flexdll/releases
250279 * Cloning the git repository by running:
251280+
252252- git clone https://github.com/ocaml/flexdll.git
281281+[source,sh]
282282+----
283283+git clone https://github.com/ocaml/flexdll.git
284284+----
253285254286 * If you are compiling from a git clone of the OCaml repository, instead of
255287 using a sources tarball, you can run:
256288+
257257- git submodule update --init
289289+[source,sh]
290290+----
291291+git submodule update --init
292292+----
258293259294OCaml is then compiled normally for the port you require.
260295261261- make
262262- make install
296296+[source,sh]
297297+----
298298+make
299299+make install
300300+----
263301264302 * `make install` will install FlexDLL by placing `flexlink.exe`
265303 (and the default manifest file for the Microsoft port) in `bin/` and the
+5-3
parsing/HACKING.adoc
···991010link:parser.mly[parser.mly]:: This file contains the grammar used to
1111generated the parser -- using the
1212-link:http://gallium.inria.fr/~fpottier/menhir/[menhir] parser
1212+link:https://gallium.inria.fr/~fpottier/menhir/[menhir] parser
1313generator, which is an external tool that you need to install if you
1414wish to modify the parser.
15151616-=== Working on the parser grammar
1616+== Working on the parser grammar
17171818To avoid depending on an external tool, the compiler build system does
1919not rebuild the parser from the source grammar link:parser.mly[] each
···2525link:../Makefile.menhir[] for the details of the various
2626Menhir-related targets and their use.
27272828-==== Testing the grammar
2828+=== Testing the grammar
29293030The root Makefile contains a `build-all-asts` target that will build,
3131for each source `.ml` or `.mli` file in the repository, a `.ml.ast` or
···3434This rule is rather slow to run, and can safely be run in parallel, so
3535we recommend using `-j` (without a number) to maximize parallelism:
36363737+[source,sh]
3738----
3839make -j build-all-asts
3940----
···5657 completely (unless you plan to check further changes) -- you can
5758 run `make clean-all-asts` to remove them.
58596060+[source,sh]
5961----
6062# save pre-change ASTs
6163make -j build-all-asts
+7-1
runtime/HACKING.adoc
···10101111If you want to use the bytecode compiler:
12121313+[source,sh]
1314----
1415# build the runtime
1516make runtime -j
···23242425If you want to use the native compiler:
25262727+[source,sh]
2628----
2729# build the native runtime
2830make runtimeopt -j
···4547link:https://ocaml.org/manual/runtime.html#s:ocamlrun-options[].
4648You can enable all printing with
47495050+[source,sh]
4851----
4952OCAMLRUNPARAM="v=0xffffffff" ./test
5053----
···5861Another useful OCAMLRUNPARAM setting is `V=1`, which enables
5962additional sanity checks on the heap during major GC cycles.
60636464+[source,sh]
6165----
6266OCAMLRUNPARAM="V=1" ./test
6367----
···8589`coredumpctl dump` will show you information about the last "core
8690dump".
87919292+[source,console]
8893----
8989-$ $ coredumpctl dump
9494+$ coredumpctl dump
9095 PID: 678260 (Domain0)
9196 UID: 1000 (gasche)
9297 GID: 1000 (gasche)
···108113109114You can get a full backtrace using `echo bt | coredumpctl debug`:
110115116116+[source,console]
111117----
112118$ echo bt | coredumpctl debug
113119[...]
+1-1
stdlib/HACKING.adoc
···66Note: All paths are given relative to the root of the repository.
7788First, build the compiler. Run `./configure`, then `make`. See
99-link:../HACKING.adoc[].
99+xref:../HACKING.adoc[].
10101111To add a new module, you must:
1212
+2-2
testsuite/HACKING.adoc
···12121313There are many kind of tests already, so the easiest way to start is
1414to extend or copy an existing test. To learn how to write new tests
1515-using ocamltest, read [OCAMLTEST.org](../ocamltest/OCAMLTEST.org).
1515+using ocamltest, read link:../ocamltest/OCAMLTEST.org[].
16161717Note: in april 2023, the test scripting language has changed: the
1818org-mode-based syntax was replaced by at C-like syntax. ocamltest
···134134| `1` or unset | 2 cores, 2 Gb RAM | 32 or 64 bits
135135| `2` | 4 cores, 4 Gb RAM | 64 bits
136136| `3` | 8 cores, 8 Gb RAM | 64 bits
137137-|=====
137137+|====
138138139139Tests, then, can check the `OCAML_TEST_SIZE` environment variable and
140140increase the number of cores or the amount of memory used. The
+2-2
typing/HACKING.adoc
···33inference. Here is a reading list to ease your discovery of the
44typechecker:
5566-http://caml.inria.fr/pub/docs/u3-ocaml/index.html[Using, Understanding, and Unraveling the OCaml Language by Didier Rémy] ::
66+https://caml.inria.fr/pub/docs/u3-ocaml/index.html[_Using, Understanding, and Unraveling the OCaml Language_ by Didier Rémy] ::
77This book provides (among other things) a formal description of parts
88of the core OCaml language, starting with a simple Core ML.
991010-http://okmij.org/ftp/ML/generalization.html[Efficient and Insightful Generalization by Oleg Kiselyov] ::
1010+https://okmij.org/ftp/ML/generalization.html[_Efficient and Insightful Generalization_ by Oleg Kiselyov] ::
1111This article describes the basis of the type inference algorithm used
1212by the OCaml type checker. It is a recommended read if you want to
1313understand the type-checker codebase, in particular its handling of
+5-2
utils/HACKING.adoc
···1919increment the version of every kind of magic number.
20202121The process for bootstrapping the compiler is covered in
2222-link:../BOOTSTRAP.adoc[BOOTSTRAP.adoc]. There is also a test script in CI which
2222+xref:../BOOTSTRAP.adoc[]. There is also a test script in CI which
2323demonstrates the process in
2424link:../tools/ci/inria/bootstrap/script[tools/ci/inria/bootstrap].
2525···5454Since https://github.com/ocaml/ocaml/pull/12652/[PR #12652], simply run
5555the following command to bump the magic numbers to version xyz:
56565757- tools/bump-magic-numbers xyz
5757+[source,sh]
5858+----
5959+tools/bump-magic-numbers xyz
6060+----
58615962Once the bootstrap during which the magic numbers have been bumped
6063has been completed, the following files need to be committed: