OCaml 4.09.0: second beta

The release of OCaml 4.09.0 is approaching. We have created a second beta version
to help you adapt your software to the new features ahead of the release.

This new beta integrates in particular the fixes from 4.08.1 that were not yet
part of the first beta due to the overlap between the release of 4.08.1 and the
first beta.

If you tried to test the first beta, and were stopped by the lack of working dune
and ocamlfind, those issues has been fixed.

The source code is available at these addresses:


The compiler can also be installed as an OPAM switch with one of the
following commands.

opam switch create ocaml-variants.4.09.0+beta2 --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git


opam switch create ocaml-variants.4.09.0+beta2+<VARIANT> --repositories=default,beta=git+https://github.com/ocaml/ocaml-beta-repository.git

where you replace <VARIANT> with one of these:

  • afl
  • default-unsafe-string
  • flambda
  • fp
  • fp+flambda

We want to know about all bugs. Please report them here:

Happy hacking.

Changes in OCaml 4.09.0

(Changes that can break existing programs are marked with a “🟎”)

Code generation and optimizations:

  • #2278: Remove native code generation support for 32-bit Intel macOS,
    iOS and other Darwin targets.
    (Mark Shinwell, review by Nicolas Ojeda Bar and Xavier Leroy)

  • #8507: Shorten symbol names of anonymous functions in Flambda mode
    (the directory portions are now hidden)
    (Mark Shinwell, review by Nicolás Ojeda Bär)

  • #7931, #1904: Add FreeBSD/aarch64 support
    (Greg V, review by Sébastien Hinderer, Stephen Dolan, Damien Doligez
    and Xavier Leroy)

  • #8547: Optimize matches that are an affine function of the input.
    (Stefan Muenzel, review by Alain Frisch, Gabriel Scherer)

  • #8681, #8699, #8712: Fix code generation with nested let rec of functions.
    (Stephen Dolan, Leo White, Gabriel Scherer and Pierre Chambart,
    review by Gabriel Scherer, reports by Alexey Solovyev and Jonathan French)

Compiler user-interface and warnings:

  • 🟎 #2276: Remove support for compiler plugins and hooks (also adds
    (Mark Shinwell, Xavier Clerc, review by Nicolás Ojeda Bär,
    Florian Angeletti, David Allsopp and Xavier Leroy)
  • #2301: Hint on type error on int literal
    (Jules Aguillon, review by Nicolás Ojeda Bär , Florian Angeletti,
    Gabriel Scherer and Armaël Guéneau)

  • #2309: New options -with-runtime and -without-runtime in ocamlopt/ocamlc
    that control the inclusion of the runtime system in the generated program.
    (Lucas Pluvinage, review by Daniel Bünzli, Damien Doligez, David Allsopp
    and Florian Angeletti)

  • #2314: Remove support for gprof profiling.
    (Mark Shinwell, review by Xavier Clerc and Stephen Dolan)

  • #3819, #8546 more explanations and tests for illegal permutation
    (Florian Angeletti, review by Gabriel Scherer)

  • #8537: fix the -runtime-variant option for bytecode
    (Damien Doligez, review by David Allsopp)

  • #8541: Correctly print multi-lines locations
    (Louis Roché, review by Gabriel Scherer)

  • #8579: Better error message for private constructors
    of an extensible variant type
    (Guillaume Bury, review by many fine eyes)

Compiler distribution build system:

  • #2267: merge generation of header programs, also fixing parallel build on
    (David Allsopp, review by Sébastien Hinderer)

  • #8514: Use boot/ocamlc.opt for building, if available.
    (Stephen Dolan, review by Gabriel Scherer)

Internal/compiler-libs changes:

  • #1579: Add a separate types for clambda primitives
    (Pierre Chambart, review by Vincent Laviron and Mark Shinwell)

  • #1965: remove loop constructors in Cmm and Mach
    (Vincent Laviron)

  • #1973: fix compilation of catches with multiple handlers
    (Vincent Laviron)

  • #2190: fix pretty printing (using Pprintast) of “lazy …” patterns and
    “fun (type t) -> …” expressions.
    (Nicolás Ojeda Bär, review by Gabriel Scherer)

  • #2228, #8545: refactoring the handling of .cmi files
    by moving the logic from Env to a new module Persistent_env
    (Gabriel Scherer, review by Jérémie Dimino and Thomas Refis)

  • #2229: Env: remove prefix_idents cache
    (Thomas Refis, review by Frédéric Bour and Gabriel Scherer)

  • #2237, #8582: Reorder linearisation of Trywith to avoid a call instruction
    (Vincent Laviron and Greta Yorsh, additional review by Mark Shinwell;
    fix in #8582 by Mark Shinwell, Xavier Leroy and Anil Madhavapeddy)

  • #2265: Add bytecomp/opcodes.mli
    (Mark Shinwell, review by Nicolas Ojeda Bar)

  • #2268: Improve packing mechanism used for building compilerlibs modules
    into the Dynlink libraries
    (Mark Shinwell, Stephen Dolan, review by David Allsopp)

  • #2277: Use newtype names as type variable names
    (Matthew Ryan)

  • #2280: Don’t make more Clambda constants after starting Cmmgen
    (Mark Shinwell, review by Vincent Laviron)

  • #2281: Move some middle-end files around
    (Mark Shinwell)

  • #2283: Add [is_prefix] and [find_and_chop_longest_common_prefix] to
    (Mark Shinwell, review by Alain Frisch and Stephen Dolan)

  • #2284: Add various utility functions to [Misc] and remove functions
    from [Misc.Stdlib.Option] that are now in [Stdlib.Option]
    (Mark Shinwell, review by Thomas Refis)

  • #2286: Functorise [Consistbl]
    (Mark Shinwell, review by Gabriel Radanne)

  • #2291: Add [Compute_ranges] pass
    (Mark Shinwell, review by Vincent Laviron)

  • #2292: Add [Proc.frame_required] and [Proc.prologue_required].
    Move tail recursion label creation to [Linearize]. Correctly position
    [Lprologue] relative to [Iname_for_debugger] operations.
    (Mark Shinwell, review by Vincent Laviron)

  • #2308: More debugging information on [Cmm] terms
    (Mark Shinwell, review by Stephen Dolan)

  • #7878, #8542: Replaced TypedtreeIter with tast_iterator
    (Isaac “Izzy” Avram, review by Gabriel Scherer and Nicolás Ojeda Bär)

  • #8598: Replace “not is_nonexpansive” by “maybe_expansive”.
    (Thomas Refis, review by David Allsopp, Florian Angeletti, Gabriel Radanne,
    Gabriel Scherer and Xavier Leroy)

Runtime system:

  • #1725, #2279: Deprecate Obj.set_tag and Obj.truncate
    (Stephen Dolan, review by Gabriel Scherer, Damien Doligez and Xavier Leroy)

  • #2075, #7729: rename _T macro used to support Unicode in the (Windows) runtime
    in order to avoid compiler warning
    (Nicolás Ojeda Bär, review by Gabriel Scherer and David Allsopp)

  • 🟎 #2240: Constify “identifier” in struct custom_operations
    (Cedric Cellier, review by Xavier Leroy)
  • #2250: Remove extra integer sign-extension in compare functions
    (Stefan Muenzel, review by Xavier Leroy)
  • 🟎 #2293: Constify “caml_named_value”
    (Stephen Dolan, review by Xavier Leroy)
  • #8607: Remove obsolete macros for pre-2002 MSVC support
    (Stephen Dolan, review by Nicolás Ojeda Bär and David Allsopp)

  • #8656: Fix a bug in [caml_modify_generational_global_root]
    (Jacques-Henri Jourdan, review by Gabriel Scherer)

  • #8787, #8788: avoid integer overflow in caml_output_value_to_bytes
    (Jeremy Yallop, report by Marcello Seri)

Standard library:

  • #2262: take precision (.) and flags (’+’ and ’ ') into account
    in printf %F
    (Pierre Roux, review by Gabriel Scherer)

  • #6148, #8596: optimize some buffer operations
    (Damien Doligez, reports by John Whitington and Alain Frisch,
    review by Jeremy Yallop and Gabriel Scherer)

Other libraries:

  • #2112: Fix Thread.yield unfairness with busy threads yielding to each
    (Andrew Hunter, review by Jacques-Henri Jourdan, Spiros Eliopoulos, Stephen
    Weeks, & Mark Shinwell)

  • #7903, #2306: Make Thread.delay interruptible by signals again
    (Xavier Leroy, review by Jacques-Henri Jourdan and Edwin Török)

  • #2248: Unix alloc_sockaddr: Fix read of uninitialized memory for an
    unbound Unix socket. Add support for receiving abstract (Linux) socket paths.
    (Tim Cuthbertson, review by Sébastien Hinderer and Jérémie Dimino)

  • #2289: Delete the vmthreads library. This library was deprecated in 4.08.0.
    (Jérémie Dimino)

  • #2318: Delete the graphics library. This library is now available
    as a separate “graphics” package in opam. Its new home is:
    (Jérémie Dimino, review by Nicolas Ojeda Bar, Xavier Leroy and
    Sébastien Hinderer)


  • #2221: ocamldep will now correctly allow a .ml file in an include directory
    that appears first in the search order to shadow a .mli appearing in a later
    include directory.
    (Nicolás Ojeda Bär, review by Florian Angeletti)

Manual and documentation:

  • #8757: Rename Pervasives to Stdlib in core library documentation.
    (Ian Zimmerman, review by David Allsopp)

  • #7584, #8538: Document .cmt* files in the “overview” of ocaml{c,opt}
    (Oxana Kostikova, rewiew by Florian Angeletti)

  • #8515: manual, precise constraints on reexported types
    (Florian Angeletti, review by Gabriel Scherer)

Bug fixes:

  • #7156, #8594: make top level use custom printers if they are available
    (Andrew Litteken, report by Martin Jambon, review by Nicolás Ojeda Bär,
    Thomas Refis, Armaël Guéneau, Gabriel Scherer, David Allsopp)

  • #3249: ocamlmklib should reject .cmxa files
    (Xavier Leroy)

  • #7937, #2287: fix uncaught Unify exception when looking for type
    (Florian Angeletti, review by Jacques Garrigue)

  • #2296: Fix parsing of hexadecimal floats with underscores in the exponent.
    (Hugo Heuzard and Xavier Leroy, review by Gabriel Scherer)

  • #8610, #8613: toplevel printing, consistent deduplicated name for types
    (Florian Angeletti, review by Thomas Refis and Gabriel Scherer,
    reported by Xavier Clerc)

  • #8635, #8636: Fix a bad side-effect of the -allow-approx option of
    ocamldep. It used to turn some errors into successes
    (Jérémie Dimino)

  • #8701, #8725: Variance of constrained parameters causes principality issues
    (Jacques Garrigue, report by Leo White, review by Gabriel Scherer)

  • #8777(partial): fix position information in some polymorphic variant
    error messages about missing tags
    (Florian Angeletti, review by Thomas Refis)

  • #8779, more cautious variance computation to avoid missing cmis
    (Florian Angeletti, report by Antonio Nuno Monteiro, review by Leo White)

  • #8800: Fix soundness bug in extension constructor inclusion
    (Leo White, review by Jacques Garrigue)

  • #8810: Env.lookup_module: don’t allow creating loops
    (Thomas Refis, report by Leo White, review by Jacques Garrigue)

  • #8848: Fix x86 stack probe CFI information in caml_c_call and
    (Tom Kelly, review by Xavier Leroy)

  • #8864, #8865: Fix native compilation of left shift by (word_size - 1)
    (Vincent Laviron, report by Murilo Giacometti Rocha, review by Xavier Leroy)

  • #8862, #8871: subst: preserve scopes
    (Thomas Refis, report by Leo White, review by Jacques Garrigue)

  • #8921, #8924: Fix stack overflow with Flambda
    (Vincent Laviron, review by Pierre Chambart and Leo White,
    report by Aleksandr Kuzmenko)


Does it have any known performance changes? Improvements or regressions?

1 Like

Nothing major comes to my mind. This release consists mostly in bug fixes, small or internal improvements, and the removal of compiler plugins. The graphics library is also no longer distributed with the compiler (but is available on opam) whereas the vmthreads libray has been entirely deprecated.

The operations of the Buffer module are slightly faster, which could result in a few percent gains on programs spending most of their time there.

The “affine function optimization” transformation should make some code in the spirit of function A -> 1 | B -> 2 | C -> 3 | D -> 4 faster than before (people could have been tempted to use unsafe casts in this situation).

There are no known performance regressions. During the beta period, finding the unknown performance regressions is the work of our esteemed users :slight_smile:

1 Like

So…no such changes? :wink:

In fact, there are some, but the asterisks were hidden by the markdow renderer . I added some 🟎 to mark those breaking changes.

1 Like

From the top of the head, do you know will it also handle functions such as

let int_of_bool = if true then 1 else 0

(I think it should), and a more complex example (I think it won’t):

let bool_of_int = function
| 0 -> false
| _ -> true

or this one (I hope it will)

let bool_of_int = function
| 0 -> false
| 1 -> true
| _ -> invalid_arg "expects 0 or 1"

A literal quote in markdown is \* like * or a quote that is surrounded by spaces like * or quoting it like `*`. :slight_smile:

@ivg unfortunately I suspect that none of your examples are handled. I noticed the first one was missing before, when I tried to implement an efficient compare function on int values. (The reason why it’s not supported is that the optimization applies on “switch” constructions emitted by the pattern-matching compiler, and a two-way branch goes through a conditional and not a switch.)

The other cases could potentially be handled by supporting piece-wise affine functions, rather than just affine functions, but that increases complexity, so I don’t think we would do it without convincing use-cases.

1 Like

I see, but what about

let int_of_bool = function
  | true -> 1
  | false -> 0

will it be handled?

No, not currently (this is again compiled into a conditional, not a switch).

That’s sad :frowning: So we will stick with bad old Obj.magic.

Or you could submit a pull-request to implement this change, and provide your use-cases for it in the discussion?

(The logic to recognize affine transformations is already there, it’s probably just a matter of reusing it in some additional situations.)


For int_of_bool, this could be done without too much trouble. If you file an issue on the bug tracker, I (or somebody else) will look at it when I get some time.

1 Like

TBH, I don’t really feel that such functions should be handled by this affine transformation mechanism. What I believe should happen is that after inlinining such computations should be eliminated by flambda, long after this affine transformation.

The make_switch function is already quite complex, I don’t think it is worthwhile to touch it for such a micro-optimization.

Update. After a second thought, maybe I’m wrong. It is not an identity function yet, therefore it couldn’t be easily eliminated by the middle-end, so probably it would be a good place to turn it into identity. I will look into it.

1 Like

by the markdow renderer

btw, <VARIANT> got eaten too.
In “ocaml-variants.4.09.0+beta2+<VARIANT>” and “where you replace <VARIANT> with one of these

Thanks, I’ve edited the post to fix the Markdown rendering of the commands.