Commit Graph

128 Commits (64f6f83f447e02d49e998f4c7ae39db4057301fe)

Author SHA1 Message Date
Stephen Dolan fd1bb255e1 More partial application warnings 2020-06-02 12:11:41 +01:00
Nicolás Ojeda Bär 9b748843bb
Use List.find_map (#9589) 2020-05-21 08:51:16 +02:00
Gabriel Scherer 8c36e799b0 revert #244
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.
2019-12-21 15:44:42 +01:00
Gabriel Scherer 9d81d6a10e new Misc.Magic_number module for magic number handling
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.
2019-12-03 00:08:29 +01:00
Gabriel Scherer f5252e9840 Misc.protect_refs: use Fun.protect to protect the backtrace
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.
2019-11-07 14:43:17 +01:00
Leo White c19e8b2350 Refactor environment lookup functions 2019-08-15 15:56:50 +01:00
Vincent Laviron 0557f07e70 Fix lsl overflow detection (#8865)
The formula for Misc.no_overflow_lsl a k is sound only if k < width of type int.
2019-08-09 09:42:11 +02:00
Leo White acd06f1eff Remove Misc.may_map and similar 2019-05-23 16:27:58 +01:00
Stefan Muenzel 5a88aeb0a5 Simplify matches that are an affine function of the input (#8547) 2019-04-09 22:52:24 +02:00
Mark Shinwell e141d9e240
Add a few utility functions in Misc (#2284) 2019-03-15 11:28:19 +00:00
Mark Shinwell 36c163248d Remove support for compiler plugins (#2276)
After consultation on the core developers' list I am proposing this patch to remove support for compiler plugins.

The main motivations for removing compiler plugins are:
- They are a potential security risk.
 - They increase the complexity of the build system and make maintenance of the Dynlink libraries more difficult (although actually, this complexity could probably be reduced after #2268 is merged).
 - Many applications of plugins should be able to be expressed by building custom compiler drivers that link against compilerlibs.

* Remove compiler plugins and hooks
* Add new function Dynlink.unsafe_get_global_symbol but keep it outside the documented API.
* Remove otherlibs/dynlink/nodynlink.ml
* Update Changes
2019-03-13 11:46:37 +01:00
Mark Shinwell c975b15de4 List prefix functions for Misc.Stdlib.List (#2283) 2019-03-06 11:59:03 +01:00
Armaël Guéneau 00411d41f4 ocamltest: explicitly set OCAML_ERROR_STYLE
Explicitly set OCAML_ERROR_STYLE to its default value when running tests,
instead of inheriting the one coming from the outside environment.
2019-02-27 15:13:56 +01:00
Gabriel Scherer dcc8a366aa env refactoring: move EnvLazy to utils/misc.ml 2019-02-16 11:40:28 +01:00
Gabriel Scherer 9847940c01 refactoring: new type aliases Misc.{filepath,modname,crcs,alerts} 2019-01-30 22:37:13 +01:00
Jeremie Dimino 7e0862a212 Refactor load path management and initial environment
- Add a Load_path module which caches files lookup

- Instead of falling back to the external environment, allow to
  declare in the environment that a module comes from the external
  world. This allows persistent structures to shadows non-persistent
  ones
2019-01-30 16:36:38 +00:00
Thomas Refis 742c65d30b List.filter_map (#2185) 2018-12-12 16:29:50 +01:00
Mark Shinwell c237f42521 Fix crc_interfaces stuff 2018-11-13 13:43:38 +00:00
Armaël Guéneau 0fa81c73d4
Merge pull request #2109 from nojb/spellchecking_disambiguation
Print full paths in spellchecking suggestions when needed for disambiguation
2018-11-05 13:23:22 +01:00
Nicolás Ojeda Bär 9f1531e20b Do not include duplicates in spelling suggestions 2018-11-01 13:34:16 +01:00
Armaël Guéneau 6b16bcc4fe Add option -error-style and environment variable OCAML_ERROR_STYLE 2018-10-20 17:11:35 +02:00
Armaël Guéneau f954160614 Add source highlighting for errors & warnings in batch mode 2018-10-19 23:38:25 +02:00
Nicolás Ojeda Bär 795a9a2190 Simplify 2018-10-10 14:55:04 +02:00
Nicolás Ojeda Bär 2bf30a2fb2 Fix regression: return empty list of directories when PATH-like env var is empty 2018-10-10 14:55:04 +02:00
Nicolás Ojeda Bär 223f2e2ffa Add Misc.split_path_contents 2018-10-10 14:54:47 +02:00
Drup bbadeee53d Introduce semantic tags as an extensible sum type. 2018-09-02 12:11:55 +02:00
Jérémie Dimino 9124ab82d1
Deprecate Pervasives (#1605)
- inline Pervasives in Stdlib and re-add Pervasives as a deprecated
module that aliases all elements of Stdlib except the stdlib modules.

- remove special case for Stdlib.Pervasives in printtyp.ml
2018-08-27 12:42:14 +01:00
Gabriel Scherer 5de54bc149
Merge pull request #1919 from gasche/fatal_error_format
Misc.fatal_error: use Format.eprintf instead of prerr_string
2018-07-30 18:08:47 +02:00
Drup abc0b7e3ed Add compile_common.ml which contains the basic compilation pipeline.
Factorize the part from compile.ml and optcompile.ml.
2018-07-27 15:07:43 +02:00
Xavier Clerc 7e29162582 Pass the elements from `BUILD_PATH_PREFIX_MAP` to the assembler (#1930) 2018-07-27 12:25:23 +02:00
François Bobot da3f9f34f5 Use reraise_raw_backtrace in Misc.try_finally
And add labels ~always for previous cleanup function and
    ~exceptionally for new cleanup function in exceptional case
2018-07-25 17:58:32 +02:00
Gabriel Radanne 1be47bf7ab Just some tbl things. (#1699) 2018-07-23 13:19:41 +01:00
Gabriel Scherer 103debaa59 Misc.fatal_error: use Format.eprintf instead of prerr_string
The use of a non-Format output caused troubles when called from the
toplevel. In comparison, Misc.fatal_errorf was already using Format,
and many files freely mix those two functions.

The suggestion comes from Florian Angeletti in #1918.

Reviewed by: ?

(no change entry needed)
2018-07-19 23:50:08 +02:00
Xavier Clerc cd06e22582 Shadow the polymorphic comparison in the middle-end (#1811) 2018-07-11 13:50:02 +02:00
Gabriel Scherer 15c89485f3
Merge pull request #1723 from stedolan/remove-meta-static
Remove Meta.static_{alloc, free}.
2018-05-28 16:14:52 +02:00
Gabriel Scherer 559206b4e0 ocamlc -config: new -config-var option to print specific configuration variables
The proposed behavior of `-config-var s` is as follows:
- if `s` is an existing configuration variable, print its value as
  a string and exit with a success return value (0)
- if `s` is not an existing configuration variable, print nothing
  and exit with a failure return value (non-0)

Note that we do not print a newline after the value of the
configuration variable. In particular, if the value is an empty
string, the output is undistinguishable from the output for
non-existing variables, the return value has to be considered instead.

The following alternative behaviors were considered:

- We could print a newline after the configuration value, which
  would let users distinguish empty values from non-existing variables
  by counting the lines of output, and would also be more pleasant for
  users invoking the option from the command-line. However, the way
  bash works on Windows means that $(ocamlc -config-var foo) would keep
  a trailing \r in its output, and portable scripts would have to use
  $(ocamlc -config-var foo | tr -d '\r') instead, which is a pain.
  (This issue was pointed out by David Allsopp)

- We could print a message on the error output if the configuration
  variable does not exist. This is clearer to a human user, but it is
  annoying for scripts if they forget to silence the error output and
  get their output mixed with our error messages. The main use of this
  new feature is for scripting purposes.
2018-04-27 19:54:08 +02:00
Stephen Dolan 7f76b23531 Add LongString.blit_string 2018-04-13 17:11:37 +01:00
Stephen Dolan aa1dc8063a Remove Meta.static_{alloc, free}.
The bytecode runtime now represents code to be loaded as LongString.t,
rather than as a naked pointer to a bytecode block.

(This commit breaks Dynlink of bytecode, due to an issue about digests)
2018-04-13 16:29:33 +01:00
Max Mouratov 7c6b2ed3e7 More robust implementation of Misc.no_overflow_mul (#1520)
* More robust implementation of Misc.no_overflow_mul

The old one fails on [a = min_int, b = -1] and [b = 0].  The new one is taken from Hacker's Delight.

* Changes: add entry

* testsuite: add tests for Misc.no_overflow_{add,sub,mul}
2017-12-20 16:45:39 +01:00
Xavier Leroy 071866c447 Create .cmi files atomically (MPR#7472) (#1307)
* MPR#7472: create .cmi files atomically

This is done by writing the data to a temporary file, compute the checksum, finish writing the data, and only then rename the temporary file to the destination .cmi file.

Writing .cmi files this way should avoid the corruption of .cmi files reported in MPR#4991.  This corruption can occur when a .cmi file is produced simultaneously by a run of ocamlc and a run of ocamlopt.

"Atomic" here means "as atomic as the underlying file system guarantees".  The atomicity guarantees of Windows file systems aren't entirely clear.

* Create .annot and .cmt files atomically, like .cmi files

Follow-up to MPR#7472.  The pattern "write to temporary file then rename"
is abstracted in the new function Misc.output_to_file_via_temporary
and applied to .cmi, .cmt and .annot files.
2017-09-06 20:01:15 +02:00
Fourchaux 72cfdd56e9 Typos and basic grammar error fixing (#1280) 2017-08-10 11:59:23 +01:00
Pierre Chambart 177713ec02 Optimize away some physical equality (#850) 2017-08-01 08:04:03 +01:00
Hannes Mehnert 76bf7c568e Respect OCAML_COLOR environment variable for deciding whether to use colors
Since 4.03, OCaml supports coloring its messages to standard output and standard
error, depending on the "-color" argument ({always,never,auto}).  This commit
adds support for the environment variable "OCAML_COLOR" (which value can as well
be {always,never,auto}).

The command line argument "-color" takes precedence, "OCAML_COLOR" is only
taken into consideration if no "-color" is provided.

The motivation for this is that the user should have control over coloring
OCaml's output messages.  OCamlbuild, a widely used build tool executes OCaml
not under a tty (and OCaml does not colorize errors and warnings), which lead
various packages use `color(always)` in their `_tags` files, which breaks with
other (non-interactive) programs (i.e.  editor helpers).

Further discussion was done at https://github.com/ocaml/ocamlbuild/issues/87 and
https://github.com/ocaml/ocaml/pull/1098.
2017-03-15 08:24:13 +00:00
alainfrisch d9f43d733e Wrap hook exceptions and have them printed with the standard mechanism instead of stopping the process. 2016-07-12 18:10:08 +02:00
Fabrice Le Fessant bfc36003aa Add hooks on some compilation phases 2016-07-12 17:59:58 +02:00
alainfrisch 19d513466e Misc.Stdlib.String.split -> String.split_on_char. 2016-07-11 15:01:32 +02:00
alainfrisch 15e83644b5 Misc.split -> String.split_on_char. 2016-07-11 14:55:40 +02:00
alainfrisch aa4f427591 Add Filename.extension and Filename.remove_extension.
The definition was suggested by Daniel Bunzli. It considers
that ".", "..", ".foo" all have an empty extension.

This commit also fixes chop_extension to align with this definition
and adds remove_extension which behaves as chop_extension but
does not fail when the extension is empty.

There used to be a Misc.chop_extension_if_any in the compiler code base.
The commit also replaces it with the new Filename.remove_extension.
2016-07-10 00:16:48 +02:00
Mark Shinwell 391d7f05a9 Fix embarrassing bug in Misc.Stdlib.String.split properly 2016-03-17 10:37:49 +00:00
Mark Shinwell 7a9f3d50da Fix embarassing bug in Misc.Stdlib.String.split 2016-03-17 10:33:31 +00:00