This lets users write code that is robust to the addition of new
geometry fields.
Format.(pp_update_geometry ppf (fun geo -> {geo with ...}))
Today the only way to set the geometry is
Format.pp_set_geometry ppf ~margin ~max_indent
we cannot add optional parameters after the [ppf] argument, and adding
new labeled parameters would break user code.
(Also: it's often convenient to work with the record directly, for
example to reset a previous geometry saved with [pp_get_geometry];
this is indirectly provided by [pp_update_geometry].)
They are somewhat difficult to handle for native allocations, and it is not clear how useful they are. Moreover, they are easy to add back since [Gc.Memprof.allocation] is a private record.
This PR was tested with also the -dsel, -dlinear output (also fixed to
not-print locations), but the output is architecture-dependent so this
part of the test was removed.
We need to make sure they do not share a page with code, otherwise the
GC and the polymorphic hash and comparison functions will follow code
pointers and potentially trigger a segfault.
The ocamltest modules depend on core-compiler modules and get linked
with compilerlibs archives, but those dependencies were not recorded
in the makefile, leading to incremental build errors.
(A particular error I encountered is that ocamltest/Ocaml_actions now
depends on Lambda through Cmo_format, but was not correctly rebuilt
after Lambda changes, leading to link-time failure when linking
ocaml_actions.cmo and ocamlcommon.cma together.)
This commit adds dependencies on the compilerlibs archives, as a proxy
for the corresponding compiler modules.
Before this PR, dynlink_compilerlibs/foo.cmi would not depend on
dynlink_compilerlibs/foo.mli, resulting in object files not being
properly recomputed in incremental-rebuild scenarios.
Before dynlink_compilerlibs/foo.mli depends on
dynlink_compilerlibs/.depend which in turn depends on all copied
source files, the present change has the impact of having the .depend
being regenerated much more often. We change its generator from
$(CAMLRUN) boot/ocamlc to $(BEST_OCAMLDEP) (using ocamlc.opt
when available); on my machine, when ocamlc.opt is available, the
.depend step goes from 0.6s to 0.2s.
Before this commit, the Makefile for compilerlibs archives only tracks
their dependencies on implementation object files (.cmo,
.cmx). .mli-only files in those directories result in a .cmi without
a .cmo.
The main makefile uses dependencies on compilerlibs archives as
a proxy for all dependencies on the corresponding compiler
modules. This assumption was broken by .mli-only modules not being
dependencies on the archives.
For example, rebuilding compilerlibs archives would not refresh
file_format/cmxs_format.cmi. The following steps would lead to a build
failure:
make core
make ocamltools
<add a new blank line at the beginning of utils/misc.mli>
make ocamltools
File "/home/gasche/Prog/ocaml/github-trunk/tools/objinfo.ml", line 1:
Error: The files /home/gasche/Prog/ocaml/github-trunk/utils/misc.cmi
and /home/gasche/Prog/ocaml/github-trunk/file_formats/cmxs_format.cmi
make inconsistent assumptions over interface Misc
The previous promised limit of ocamlyacc was 256 entry points, but
on some platforms (x86 at least) the actual limit was 127 due to representation of
bucket->entry as char. Switching to unsigned char extends the limit to 255.
I introduced a constant MAX_ENTRY_POINT as a synonym of MAXCHAR to
handle checks against the limit consistently over the different modules
of ocamlyacc.
Extensions beyond 255 entry points would require a bit more work (which
looks unrewarding) since entry points are currently identified by a single byte
at the beginning of the input stream.
Fixes: #9207
The logic in this patch is wrong:
- setting the margins is not the responsibility of the color-handling code
- because setup_colors is called at inpredictable times (on the first error/warning),
the logic makes it very difficult to correctly set margins for `{str,err}_formatter`
The patch was originally proposed in the caml-list discussion
https://sympa.inria.fr/sympa/arc/caml-list/2015-09/msg00164.html
but it does not convincingly solve the problem:
- there is no reason to use `std_formatter`
rather than `err_formatter` as a reference, and
- the user can set the both margins themselves anyway.
In particular, since the 4.08 changes to error/warning
representations, we don't use intermediary formatters anymore to
produce error/warning messages, so setting `Formatter.std_formatter`
directly works as expected *when* this formatter is used to print to
the toplevel (the current default, which may change in the future).
Note: We have an API in `Location` to access and configure
error/warning formatters, but it is not accessible from the
toplevel. Changing the margins without using this API is fragile.
For example, utop and expect-tests change the formatter away from the
default.
The user can register several callbacks, which are called for various
events during the block's lifetime. We need to maintain a data
structure for tracked blocks in the runtime. When using threads,
callbacks can be called concurrently in a reentrant way, so the
functions manipulating this data structure need to be reentrant.
This commit modifies objinfo_helper so that the caml_plugin_header
symbol is also looked up in the static symbol table, if it is
not found in the dynamic one.
This is useful e.g. on Windows where the symbol can not be found
without this commit.
It is also necessary to look for the _-prefixed version of the symbol.
When passed an object file that comes from a different OCaml version,
objinfo will currently just detect that the magic number is not what
it expects, and claim it is not a valid file. This is irritating.
The error message output by objinfo now looks like this:
File /home/gasche/.opam/4.08.0/lib/astring/astring.cmi
Wrong magic number:
this tool only supports object files produced by compiler version
4.11.0+dev0-2019-10-18
This seems to be a compiled interface file (cmi) for an older version of OCaml.
This module was originally inspired by js_of_ocaml Misc.MagicNumber module
https://github.com/ocsigen/js_of_ocaml/blob/151b811/compiler/util.cppo.ml#L277-L347
It provides parsing and validation function for magic numbers, that
can tell the difference between "not a valid magic number" and "a
valid magic number, but with another version", and print user-friendly
user messages about it.
It does not contain any knowledge for where to find the magic number
in an OCaml file (this depends on the file format); the parsing
function should be called with an input channel already at the right
position for whichever format is expect.
Prefix may be passed to configure using a Cygwin-style PATH (e.g.
`./configure --prefix ~/local`). Use cygpath to ensure that the correct
version gets written to Makefile.config, or the resulting compiler has
an invalid default stdlib path.
Before, `man Map` would show:
```
For instance: module IntPairs = struct type t = int * int let compare (x0,y0) (x1,y1) = match Stdlib.compare x0 x1 with 0 -> Stdlib.compare y0 y1 |
c -> c end module PairsMap = Map.Make(IntPairs) let m = PairsMap.(empty |> add (0,1) hello |> add (1,0) world )
```
Now it shows:
```
For instance:
module IntPairs =
struct
type t = int * int
let compare (x0,y0) (x1,y1) =
match Stdlib.compare x0 x1 with
0 -> Stdlib.compare y0 y1
| c -> c
end
module PairsMap = Map.Make(IntPairs)
let m = PairsMap.(empty |> add (0,1) "hello" |> add (1,0) "world")
```
(in both cases the code is in bold)
Example:
module Test : sig
exception Foo
end = struct
end
Before this PR:
Modules do not match: sig end is not included in sig exception Foo end
The extension constructor `Foo' is required but not provided
After this PR (second line changed):
Modules do not match: sig end is not included in sig exception Foo end
The exception `Foo' is required but not provided
Currently Fun.protect and Misc.try_finally can be used in code that
tries carefully to preserve the first-failure backtrace, but
Misc.protect_refs cannot. This PR fixes the discrepancy. See #9057 for
a use-case.
See the GPR ( https://github.com/ocaml/ocaml/pull/9060 ) for an
in-depth discussion of the potential performance impact of this
change.
The show directive now has some basic facility to show
useful information for constructors of "normal" values,
exceptions and other non-exception extension constructors.
Also updated show_type to print out recursion status
with a default of Trec_first.
There is a small, desirable change of behavior in this PR:
we do not backtrack on all wildcard pattern explosions,
only on those where ppat_of_type knows there will be GADTs.
As a result, some exhaustivity counter-examples
have been improved with more cases (see testsuite for an example).
Value patterns match on a value (the result of computation), while
computation patterns handle the effects (hint hint) of
a computation. The only forms of computation patterns in OCaml today
are value patterns and exception patterns (exception p).
The sub-pattern `p` of the `lazy p` construction should be
a computation pattern, rather than a value pattern. This pull-request
does not make this change.
Most of the changes in this PR are boilerplate -- it really is a lot
of work now to add a new syntactic category to the typed-tree
syntax. This boilerplate is fairly automatic and should be easy to
review.
There is a subtle part to the patch, though: the implementation of the
pattern type-checking. It now has to reconstruct the value/computation
distinction (absent from the parse-tree), and return values from two
different types. Instead of splitting the type-checker in several
functions (which risked code duplications), I choose to use a GADT to
have the same [type_pat] function return two different types depending
on the caller. This is the least invasive way to adapt this part of
the codebase, whose inherent complexity is so large (unfortunately)
that adding a GADT to the mix barely makes a difference.
ocamltest maintains a list of "subdirectories where .cmi files of
compilerlibs modules are", and uses "include ocamlcommon" to make the
content of ocamlcommon.cma available.
The present PR updates the list of subdirectories (driver/ was not
included, so Compmisc.initial_env() was unusable) and creates modifier
names (like "ocamlcommon") for all compilerlibs archives.
The issue #9050 comes (partly) from #2281 forgetting to add the
compilerlibs/ocamlmiddleend archives in the installation target. The
present patch should solve this issue once and for all, by using
a wildcard to install all archives that have been built in
compilerlibs/, instead of using a manual listing.
Compared to trunk, the following extra files are installed in
$(LIBDIR)/compilerlibs: ocamlmiddleend.{a,cma,cmxa}. There are no
other changes in the installed-files list.
Locations of inlined frames are now represented as contiguous
sequences rather than linked lists.
The frame tables now refer to debug info by 32-bit offset rather
than word-sized pointer.
This type describes the parameter space of the [type_pat] function
(which type-checks of patterns, and in fact does quite a bit more) in
a way that also documents its behavior.
The code ends up being slightly more verbose at places: it's always
shorter to access one of four independent arguments than to go get the
information inside one record structure. But now it is clear which
parameters are meaningful in which situation, and I believe the code
is easier to read.
(This is joint work with Florian Angeletti)
Warning 30 warns when the same constructor/label is used in two
mutually-recursive type declarations. This warning (added in OCaml
3.12, 2010) was meaningful at the time where constructor/label
conflicts had a shadowing semantics: the "last" definition would mean,
while ideally mutually-recursive definitions should not be strictly
ordered but defined "all at once".
Since OCaml 4.01 (2013) we support type-based disambiguation of
constructor/label names and it is now common to write code such as,
say
type pattern = Var of var | ...
type expr = Var of var | ...
(no warning, of course). But warning 30 fires if you instead write
type pattern = Var of var | ...
and expr = Var of var | ...
This doesn't make much sense, and in particular it certainly makes no
sense to enable this warning by default. The present PR disables it by
default.
In 8691, caml_check_urgent_gc was merged with the function that runs
asynchronous callbacks. The rationale was that caml_check_urgent_gc
already runs finalisers, and so could have run any asynchronous
callbacks.
We agreed on a different strategy: we know that users could not rely
on asynchronous callbacks being called at this point, so take the
opportunity to make it callback-safe, like was done for allocation
functions.
The new check_urgent_gc no longer calls finalisers (nor any
callbacks), and instead two internal functions are introduced:
* caml_do_urgent_gc_and_callbacks : function to perform actions
unconditionally.
* caml_check_urgent_gc_and_callbacks : function that checks for
something to do, and then executes all actions (GC and callbacks).
The typedef was guarded by CAML_INTERNALS, but given its accidental use
in the public Is_young macro, mark the typedef as deprecated in case
CAML_INTERNALS is being defined "in the wild" to workaround this.
This transformation is incorrect for certain large values of x,
as it can get the wrong value in the high bit. In certain cases
where the high bit is not used (esp. storing a byte into a string),
the transformation is kept intact.
Fixes#9028.
The previous mechanism worked for C calls that raise an exception, but not for C calls that call back into OCaml code which raises an exception.
This commit addresses the issue by saving the PC in the interpreter stack before a C call, so that the backtrace mechanism always sees it.
However, if an external is declared in the .ml file and exposed in the .mli file as a val, then ocamlc generates a wrapper that adds a spurious entry in the stack frame. In this PR, this change in behavior results in the re-declaration of Printexc.get_callstack as an external instead of a val, so that the spurious stack frame does not appear in call stacks obtained from Printexc.get_callstack.
The Git configuration value ocaml.configure-cache can be used to specify
a directory to keep autoconf cache files in, relative to the worktree
root (so `git config ocaml.configure-cache .` enables the feature, and
`git config --global ocaml.configure-cache ..` enables it for all
worktrees, assuming they're at the same level).
autoconf's --cache-file option speeds up future runs of configure by
caching the results of previous tests. The cache is invalidated if any
environment variables differ (e.g. LDFLAGS) or if the build-host-target
triplet differs. This is a nuisance on Windows, where configure is both
very slow and it's also common to build with multiple different --host
values.
This PR allows a tree to be quickly reconfigured from one Windows port
to another.
The Git configuration value ocaml.configure is now passed to the
configure script's arguments before $@ if (and only if) OCaml is being
configured from a Git clone.
This allows, for example:
- Developer-specific preferences (e.g. `--disable-ocamldoc` or
`--disable-debug-runtime`)
- Automatic use of autoconf cach files (-C option)
It is implemented by inserting a test at the top of `configure`, which
is bypassed if `.git` doesn't exist.