text stringlengths 10 16.2k |
|---|
##### Evaluation order
Beware that the tail-modulo-cons transformation has an effect on evaluation order: the constructor argument that is transformed into tail-position will always be evaluated last. Consider the following example:
type 'a two_headed_list = \| Nil \| Consnoc of 'a \* 'a two_headed_list \* 'a let\[@tai... |
##### Why tail-modulo-cons?
Other program transformations, in particular a transformation to continuation-passing style (CPS), can make all functions tail-recursive, instead of targeting only a small fragment. Some reasons to provide builtin support for the less-general tail-mod-cons are as follows:
- The tail-mod-co... |
##### Note: OCaml call stack size
In OCaml 4.x and earlier, bytecode programs respect the stack_limit runtime parameter configuration (as set using Gc.set in the example above), or the l setting of the OCAMLRUNPARAM variable. Native programs ignore these settings and only respect the operating system native stack limit... |
## 1 Disambiguation
It may happen that several arguments of a constructor are recursive calls to a tail-modulo-cons function. The transformation can only turn one of these calls into a tail call. The compiler will not make an implicit choice, but ask the user to provide an explicit disambiguation.
Consider this type of... |
## 1 Disambiguation
Be aware that the resulting function is *not* tail-recursive, the recursive call on def will consume stack space. However, expression trees tend to be right-leaning (lots of Let in sequence, rather than nested inside each other), so putting the call on body in tail position is an interesting improve... |
## 2 Danger: getting out of tail-mod-cons
Due to the nature of the tail-mod-cons transformation (see Section [26.3](#sec%3Adetails) for a presentation of transformation):
- Calls from a tail-mod-cons function to another tail-mod-cons function declared in the same recursive-binding group are transformed into tail cal... |
## 2 Danger: getting out of tail-mod-cons
Warning 71 \[unused-tmc-attribute\]: This function is marked @tail_mod_cons but is never applied in TMC position. Warning 72 \[tmc-breaks-tailcall\]: This call is in tail-modulo-cons position in a TMC function, but the function called is not itself specialized for TMC, so the c... |
## 2 Danger: getting out of tail-mod-cons
Warning 71 \[unused-tmc-attribute\]: This function is marked @tail_mod_cons but is never applied in TMC position. Warning 72 \[tmc-breaks-tailcall\]: This call is in tail-modulo-cons position in a TMC function, but the function called is not itself specialized for TMC, so the c... |
## 2 Danger: getting out of tail-mod-cons
let\[@tail_mod_cons\] rec map_vars f exp = let\[@tail_mod_cons\] self exp = map_vars f exp in match exp with \| Var v -> Var (f v) \| Let ((v, def), body) -> Let ((f v, self def), (self\[@tailcall\]) body)
In other cases, there is either no benefit in making the called function... |
## 2 Danger: getting out of tail-mod-cons
type 'a tree = Leaf of 'a \| Node of 'a tree \* 'a tree let\[@tail_mod_cons\] rec bind (f : 'a -> 'a tree) (t : 'a tree) : 'a tree = match t with \| Leaf v -> (f\[@tailcall false\]) v \| Node (left, right) -> Node (bind f left, (bind\[@tailcall\]) f right) |
## 3 Details on the transformation
To use this advanced feature, it helps to be aware that the function transformation produces a specialized function in destination-passing-style.
Recall our map example:
let rec map f l = match l with \| \[\] -> \[\] \| x :: xs -> let y = f x in y :: map f xs
Below is a description of... |
## 3 Details on the transformation
Notice that map does not call itself recursively, it calls map_dps. Then, map_dps calls itself recursively, in a tail-recursive way.
The call from map to map_dps is *not* a tail call (this is something that we could improve in the future); but this call happens only once when invoking... |
## 4 Current limitations |
##### Purely syntactic criterion
Just like tail calls in general, the notion of tail-modulo-constructor position is purely syntactic; some simple refactoring will move calls out of tail-modulo-constructor position.
(\* works as expected \*) let\[@tail_mod_cons\] rec map f li = match li with \| \[\] -> \[\] \| x :: xs -... |
##### Local, first-order transformation
When a function gets transformed with tail-mod-cons, two definitions are generated, one providing a direct-style interface and one providing the destination-passing-style version. However, not all calls to this function in tail-modulo-cons position will use the destination-passin... |
## 4 Current limitations
These limitations may be an issue in more complex situations where mutual recursion happens between functions, with some functions not annotated tail-mod-cons, or defined across different modules, or called indirectly, for example through function parameters. |
##### Non-exact calls to tupled functions
OCaml performs an implicit optimization for “tupled” functions, which take a single parameter that is a tuple: let f (x, y, z) = .... Direct calls to these functions with a tuple literal argument (like f (a, b, c)) will call the “tupled” function by passing the parameters direc... |
## 4 Current limitations
------------------------------------------------------------------------ |
# OCaml - Runtime detection of data races with ThreadSanitizer
Source: https://ocaml.org/manual/5.2/tsan.html
☰
- [Batch compilation (ocamlc)](comp.html)
- [The toplevel system or REPL (ocaml)](toplevel.html)
- [The runtime system (ocamlrun)](runtime.html)
- [Native-code compilation (ocamlopt)](native.html)
- ... |
# Chapter 27 Runtime detection of data races with ThreadSanitizer |
## 1 Overview and usage
OCaml, since version 5.0, allows shared-memory parallelism and thus mutation of data shared between multiple threads. This creates the possibility of data races, i.e., unordered accesses to the same memory location with at least one of them being a write. In OCaml, data races are easy to introdu... |
## 1 Overview and usage
A TSan-enabled compiler differs from a regular compiler in the following way: all programs compiled by ocamlopt are instrumented with calls to the TSan runtime, and TSan will detect data races encountered during execution.
For instance, consider the following program:
let a = ref 0 and b = ref 0... |
## 1 Overview and usage
Previous read of size 8 at 0x8febe0 by main thread (mutexes: write M86):
#0 camlSimple_race.d1_271 simple_race.ml:5 (simple_race.exe+0x420a22)
#1 camlSimple_race.entry simple_race.ml:13 (simple_race.exe+0x420d16)
#2 caml_program <null> (simple_race.exe+0x41ffb9)
... |
## 1 Overview and usage
If you run the above program several times, the output may vary: sometimes TSan will report two data races, sometimes one, and sometimes none. This is due to the combination of two factors:
- First, TSan reports only the data races encountered during execution, i.e., conflicting, unordered mem... |
## 2 Performance implications
TSan instrumentation imposes a non-negligible cost at runtime. Empirically, this cost has been observed to cause a slowdown which can range from 2x to 7x. One of the main factors of high slowdowns is frequent access to mutable data. In contrast, the initialising writes to and reads from im... |
## 3 False negatives and false positives
As illustrated by the previous example, TSan will only report the data races encountered during execution. Another important caveat is that TSan remembers only a finite number of memory accesses per memory location. At the time of writing, this number is 4. Data races involving ... |
## 4 Runtime options
TSan supports a number of configuration options at runtime using the TSAN_OPTIONS environment variable. TSAN_OPTIONS should contain one or more options separated by spaces. See the [documentation of TSan flags](https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags) and the [documentation o... |
## 5 Guidelines for linking
As a general rule, OCaml programs instrumented with TSan should only be linked with OCaml or C objects also instrumented with TSan. Doing otherwise may result in crashes. The only exception to this rule are C libraries that do not call into the OCaml runtime system in any way, i.e., do not a... |
## 6 Changes in the delivery of signals
TSan intercepts all signals and passes them down to the instrumented program. This overlay from TSan is not always transparent for the program. Synchronous signals such as SIGSEV, SIGILL, SIGBUS, etc. will be passed down immediately, whereas asynchronous signals such as SIGINT wi... |
# OCaml - The core library
Source: https://ocaml.org/manual/5.2/core.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regular expressions and string processing](libstr... |
# Chapter 28 The core library
This chapter describes the OCaml core library, which is composed of declarations for built-in types and exceptions, plus the module Stdlib that provides basic operations on these built-in types. The Stdlib module is special in two ways:
- It is automatically linked with the user’s object... |
## 1 Built-in types and predefined exceptions
The following built-in types and predefined exceptions are always defined in the compilation environment, but are not part of any module. As a consequence, they can only be referred by their short names. |
### Built-in types
type int
> The type of integer numbers.
type char
> The type of characters.
type bytes
> The type of (writable) byte sequences.
type string
> The type of (read-only) character strings.
type float
> The type of floating-point numbers.
type bool = false | true
> The type o... |
### Built-in types
> The type of format strings. 'a is the type of the parameters of the format, 'f is the result type for the printf-style functions, 'b is the type of the first argument given to %a and %t printing functions (see module [Printf](../5.2/api/Printf.html)), 'c is the result type of these functions, and a... |
### Predefined exceptions
exception Match_failure of (string * int * int)
> Exception raised when none of the cases of a pattern-matching apply. The arguments are the location of the match keyword in the source code (file name, line number, column number).
exception Assert_failure of (string * int * int)
> Exce... |
### Predefined exceptions
> Exception raised by the bytecode interpreter when the evaluation stack reaches its maximal size. This often indicates infinite or excessively deep recursion in the user’s program. Before 4.10, it was not fully implemented by the native-code compiler.
exception Sys_error of string
> Excep... |
## 2 Module Stdlib: the initially opened module
- [Module Stdlib](../5.2/api/Stdlib.html): the initially opened module
------------------------------------------------------------------------
[« Runtime detection of data races with ThreadSanitizer](tsan.html)[The standard library »](stdlib.html)
Copyright © 2024 Inst... |
# OCaml - The standard library
Source: https://ocaml.org/manual/5.2/stdlib.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regular expressions and string processing](... |
# Chapter 29 The standard library
This chapter describes the functions provided by the OCaml standard library. The modules from the standard library are automatically linked with the user’s object code files by the ocamlc command. Hence, these modules can be used in standalone programs without having to add any .cmo fi... |
# Chapter 29 The standard library
- [Module Complex](../5.2/api/Complex.html): complex numbers
- [Module Condition](../5.2/api/Condition.html): condition variables to synchronize between threads
- [Module Domain](../5.2/api/Domain.html): Domain spawn/join and domain local variables
- [Module Digest](../5.2/api/... |
# Chapter 29 The standard library
- [Module ListLabels](../5.2/api/ListLabels.html): list operations (with labels)
- [Module Map](../5.2/api/Map.html): association tables over ordered types
- [Module Marshal](../5.2/api/Marshal.html): marshaling of data structures
- [Module MoreLabels](../5.2/api/MoreLabels.htm... |
# Chapter 29 The standard library
- [Module StdLabels](../5.2/api/StdLabels.html): include modules Array, List and String with labels
- [Module String](../5.2/api/String.html): string operations
- [Module StringLabels](../5.2/api/StringLabels.html): string operations (with labels)
- [Module Sys](../5.2/api/Sys.... |
# OCaml - The compiler front-end
Source: https://ocaml.org/manual/5.2/parsing.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regular expressions and string processin... |
# Chapter 30 The compiler front-end
This chapter describes the OCaml front-end, which declares the abstract syntax tree used by the compiler, provides a way to parse, print and pretty-print OCaml code, and ultimately allows one to write abstract syntax tree preprocessors invoked via the -ppx flag (see chapters [13](co... |
# Chapter 30 The compiler front-end
- [Module Location](../5.2/api/compilerlibref/Location.html): source code locations
- [Module Longident](../5.2/api/compilerlibref/Longident.html): long identifiers
- [Module Parse](../5.2/api/compilerlibref/Parse.html): OCaml syntax parsing
- [Module Parsetree](../5.2/api/co... |
# OCaml - The unix library: Unix system calls
Source: https://ocaml.org/manual/5.2/libunix.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regular expressions and str... |
# Chapter 31 The unix library: Unix system calls
The unix library makes many Unix system calls and system-related library functions available to OCaml programs. This chapter describes briefly the functions provided. Refer to sections 2 and 3 of the Unix manual for more details on the behavior of these functions.
- ... |
# Chapter 31 The unix library: Unix system calls
| ... |
# Chapter 31 The unix library: Unix system calls
------------------------------------------------------------------------
[« The compiler front-end](parsing.html)[The str library: regular expressions and string processing »](libstr.html)
Copyright © 2024 Institut National de Recherche en Informatique et en Automatique
... |
# OCaml - The str library: regular expressions and string processing
Source: https://ocaml.org/manual/5.2/libstr.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regul... |
# Chapter 32 The str library: regular expressions and string processing
The str library provides high-level string processing functions, some based on regular expressions. It is intended to support the kind of file processing that is usually performed with scripting languages such as awk, perl or sed.
Programs that use... |
# OCaml - The runtime_events library
Source: https://ocaml.org/manual/5.2/runtime_events.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regular expressions and strin... |
# Chapter 33 The runtime_events library
The runtime_events library provides an API for consuming runtime tracing and metrics information from the runtime. See chapter [25](runtime-tracing.html#c%3Aruntime-tracing) for more information.
Programs that use runtime_events must be linked as follows:
ocamlc -I +... |
# OCaml - The threads library
Source: https://ocaml.org/manual/5.2/libthreads.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str library: regular expressions and string processin... |
# Chapter 34 The threads library
The threads library allows concurrent programming in OCaml. It provides multiple threads of control (also called lightweight processes) that execute concurrently in the same memory space. Threads communicate by in-place modification of shared data structures, or by sending and receiving... |
# Chapter 34 The threads library
[« The runtime_events library](runtime_events.html)[The dynlink library: dynamic loading and linking of object files »](libdynlink.html)
Copyright © 2024 Institut National de Recherche en Informatique et en Automatique
--------------------------------------------------------------------... |
# OCaml - The dynlink library: dynamic loading and linking of object files
Source: https://ocaml.org/manual/5.2/libdynlink.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str libr... |
# Chapter 35 The dynlink library: dynamic loading and linking of object files
The dynlink library supports type-safe dynamic loading and linking of bytecode object files (.cmo and .cma files) in a running bytecode program, or of native plugins (usually .cmxs files) in a running native program. Type safety is ensured by... |
# Chapter 35 The dynlink library: dynamic loading and linking of object files
Copyright © 2024 Institut National de Recherche en Informatique et en Automatique
------------------------------------------------------------------------ |
# OCaml - Recently removed or moved libraries (Graphics, Bigarray, Num, LablTk)
Source: https://ocaml.org/manual/5.2/old.html
☰
- [The core library](core.html)
- [The standard library](stdlib.html)
- [The compiler front-end](parsing.html)
- [The unix library: Unix system calls](libunix.html)
- [The str librar... |
# Chapter 36 Recently removed or moved libraries (Graphics, Bigarray, Num, LablTk)
This chapter describes three libraries which were formerly part of the OCaml distribution (Graphics, Num, and LablTk), and a library which has now become part of OCaml’s standard library, and is documented there (Bigarray). |
## 1 The Graphics Library
Since OCaml 4.09, the graphics library is distributed as an external package. Its new home is:
[https://github.com/ocaml/graphics](https://github.com/ocaml/graphics)
If you are using the opam package manager, you should install the corresponding graphics package:
opam install graph... |
## 2 The Bigarray Library
As of OCaml 4.07, the bigarray library has been integrated into OCaml’s standard library.
The bigarray functionality may now be found in the standard library [Bigarray module](../5.2/api/Bigarray.html), except for the map_file function which is now part of the [Unix library](libunix.html#c%3Au... |
## 3 The Num Library
The num library implements integer arithmetic and rational arithmetic in arbitrary precision. It was split off the core OCaml distribution starting with the 4.06.0 release, and can now be found at [https://github.com/ocaml/num](https://github.com/ocaml/num).
New applications that need arbitrary-pre... |
## 4 The Labltk Library and OCamlBrowser
Since OCaml version 4.02, the OCamlBrowser tool and the Labltk library are distributed separately from the OCaml compiler. The project is now hosted at [https://github.com/garrigue/labltk](https://github.com/garrigue/labltk).
-----------------------------------------------------... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.