77 Commits

Author SHA1 Message Date
Jérôme Vouillon
699baf8866
Bytecode: more optimization hints (immediate reads, variant tests) (#15122)
* Bytecode: hint reads of immediate values

Keep in the bytecode hints the information, known in Lambda, that a
value read from a block field or from an array is an immediate:

- Hint_immediate is recorded on GETFIELD (including the fused
  GETGLOBALFIELD and PUSHGETGLOBALFIELD) when the field is Immediate,
  and on GETVECTITEM for integer arrays;
- the new C call hint Hint_immediate_result is attached to
  caml_array_get_addr for integer arrays.

This lets a compiler from bytecode, such as wasm_of_ocaml, know that
these values are integers, and use an unboxed representation for them.
To carry the information, Kgetfield and Kgetvectitem take the
immediate_or_pointer of the value read.

* Testsuite: dumpobj test for the hints on reads of immediate values

* Bytecode: hint the tests of whether a variant value is an immediate

Add to Pisint a [variant_only] flag, true when the argument is known to
be a value of a variant type, as in flambda-backend. The
pattern-matching compiler sets it for the tests it generates on
constructors and polymorphic variants; %obj_is_int and the inlined
forcing of lazy values (whose result can be any immediate) do not.

Keep this information in the bytecode hints: ISINT gets the new
Hint_variant hint when the flag is set.

A compiler from bytecode where some integers are boxed can then test
whether such a value is an immediate with a single check, since constant
constructors are never boxed. This is the case of an experimental
version of wasm_of_ocaml with 63-bit integers, where large integers are
boxed: testing whether any value is an immediate takes two type tests,
and, when the value is a block, both are performed.

* Testsuite: dumpobj test for the hints on tests of variant values

* Changes entry for #15122
2026-10-02 15:12:29 +02:00
Zane Hambly
08c54e551d
Convert between floats and boxed integers without calling into C (#15084)
* Add primitives converting between floats and boxed integers

* Use the new primitives for Int64.of_float and friends

* Changes entry for #15084

* Bootstrap

* Keep the C call for Int32.of_float
2026-09-29 19:30:16 +02:00
Zane Hambly
8155ef1d71
Generate native Iatomic_fetch_add across all architectures (#14575)
* Add Iatomic_fetch_add machine operation for native atomics

This is the machine-level infrastructure for compiling atomic
fetch-and-add to native instructions instead of C runtime calls.

* Add TSan instrumentation for Iatomic_fetch_add

* amd64: add caml_domain_alone fast path for Iatomic_fetch_add

* arm64: add trailing dmb st release barrier to fetch-and-add

* power, riscv: trailing release fence after atomic fetch-and-add
2026-06-25 12:14:45 +02:00
Stefan Muenzel
52bca5a54c Introduce additional reset functions in lambda and out_type 2026-06-18 08:39:23 +02:00
hhugo
c5b039b7c2
Propagate physical comparison operators to lambda (#13588)
Co-authored-by: Olivier Nicole <olivier@chnik.fr>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-02 15:29:10 +02:00
Gabriel Scherer
f960110a60 [refactor] Helper to reify atomic locations. 2026-03-17 22:32:47 +01:00
Clément
0902783e22 Add primitives Pcheckbound and "%check_array_bound". 2026-03-17 22:32:40 +01:00
David Allsopp
f47a07e36c Add %standard_library_default
%standard_library_default allows Config.standard_library_default to be
converted to a compile-time derived value, as with existing compile-time
constants such as %backend_type, etc. This paves the way for allowing
Config.standard_library_default to be changed at link-time, rather than
fixed when the Config module itself is compiled.
2025-12-05 10:58:32 +00:00
Vincent Laviron
5eefdf28fc Remove Lambda.Const_base indirection 2025-09-23 16:20:13 +02:00
Vincent Laviron
59ae1d7942 Introduce Lambda.constant type
This is a copy of Asttypes.constant minus the string case.
It ensures that there is a single way to represent constant strings,
and allows to remove a few pieces of duplicated code.
2025-09-23 16:20:13 +02:00
Vincent Laviron
60e044e1bf Introduce Lambda.lambda_of_const
This helper function ensures that constant strings are always
represented using Const_immstring and not Const_base (Const_string _)
2025-09-23 16:10:53 +02:00
Stephen Dolan
be625238bb Allow strings to be shared by Lambda.make_key
Strings have been immutable for a while now
2025-09-23 13:19:50 +01:00
Gabriel Scherer
6edeb97b97 [refactor] Lambda: merge transl_mod_field and transl_prim 2025-04-08 11:50:15 +02:00
Gabriel Scherer
1e6da84197 [refactoring] Lambda.transl_mod_field, move 'lazy' to clients 2025-04-08 11:50:15 +02:00
Gabriel Scherer
5270d8b5af [refactoring] move Matching.get_mod_field to Lambda.transl_mod_field 2025-04-08 11:50:15 +02:00
Vincent Laviron
979ce41050
Use a dedicated primitive for Lazy blocks (#13867)
Lazy blocks are very special, in that a value bound to a lazy block may,
at any moment, completely change its shape (it could become an immediate,
or any other kind of value).
By splitting these blocks from the regular blocks, we allow the middle-end
to assume that any Pmakeblock behaves as a normal block, making all
related optimisations safer.

In passing, this also fixes an issue with Forward blocks in recursive definitions.
2025-03-19 21:38:16 +01:00
Ulysse Gérard
0c5ae452e4 Attach new locs to Ldot and Lapply nodes
instead of `Lident` nodes.

Parser changes.
Requires bootstrap.

Co-authored-by: Jules Aguillon <jules@j3s.fr>
Suggested-by: Florian Angeletti <florian.angeletti@inria.fr>
2025-02-20 13:30:06 +01:00
Gabriel Scherer
11dcf188b2 [refactoring] simplify the Patomic_load primitive by dropping immediate info
The Patomic_load primitive represents atomic loads (Atomic.get), and
it tracks whether the load type only contains immediate values, or
whether it contains both immediates and pointers. This comes at a
small cost in complexity in the compiler source, but is in fact
completely useless for two reasons:

1. We made a mistake in atomic.mli, which results in the information
   *never* being upgraded to Immediate: we declare
   `val get : 'a t -> 'a` instead of `external get : ...`,
   and as a consequence the compiler never specializes this primitive.

   (You can test this by compiling
     `let f (n : int Atomic.t) = Atomic.get n`
    and looking at the lambda or cmm output.)

2. The backend does not in fact depend on whether the value is
   immediate or not: even if we did track this information correctly,
   there would be no change in the generated code.
   (We checked this by reviewing atomic-load code production in all
   emit.mlp backends.)

This simplification will help (modestly) simplify the code of an
upcoming PR on atomic record fields.

Co-authored-by: Clément Allain <clef-men@orange.fr>
Reviewed-by: KC Sivaramakrishnan <kc@kcsrk.info>
2024-08-27 17:01:04 +02:00
Gabriel Scherer
5c888e797f [refactor] simplify the definition of atomic functions
In trunk, all atomic functions exposed in the runtime are also exposed
as language primitives in our intermediate representations (lambda,
clambda). But except for `Patomic_load`, which benefits from
dedicated code generation, they are all transformed into C calls
on all backends.

The present PR simplifies the code noticeably by removing the
intermediate primitives, by producing C calls directly in
lambda/translprim.ml.

This reduces the amount of boilerplate to modify to implement
atomic record fields (https://github.com/ocaml/RFCs/pull/39).

Co-authored-by: Clément Allain <clef-men@orange.fr>
2024-08-24 17:55:20 +02:00
KC Sivaramakrishnan
38972e8831 Move is_evaluated to lambda 2024-05-07 14:08:16 +05:30
Nick Barnes
0ddab1ba00 Add a "%poll" primitive, which does a GC poll (and therefore runs any
pending runtime actions).
2024-04-10 13:26:26 +01:00
Vincent Laviron
d6b7459a48
Compile recursive bindings in Lambda (#12596) 2024-01-29 23:03:01 +01:00
Vincent Laviron
100558ca56 Refactoring:
- Add Value_rec_types modules
- Rename Rec_check to Value_rec_check
2023-11-24 14:16:28 +01:00
Nick Roberts
84daf9e092 Turn off arity fusion for [fun] and [function] 2023-10-16 17:24:05 +01:00
Vincent Laviron
04e0e5dcbe
Propagate the classification from Rec_check (#12551) 2023-09-25 17:53:02 +02:00
Anton Yabchinskiy
08276afddb Support 16-bit floating-point numbers as elements of bigarrays (#10775) 2023-06-19 14:36:02 +02:00
Nick Roberts
c46f38908a Remove Lev_module_definition 2023-03-13 14:29:04 +00:00
Stephen Dolan
4a89198f75 Make Lambda.lfunction private 2022-02-12 15:16:19 +01:00
Tom Kelly
9fd98fc226 Merge commit 'edf0075888ec27a50c4f50f76dba46f730797651' into 5.00_rebase_to_pr 2021-12-20 16:38:51 +00:00
Tom Kelly
6ded93883a Merge commit '2bcef4bc172f476217f253d24cb3311eaca504bf' into 5.00_rebase_to_pr 2021-12-20 15:43:01 +00:00
Sadiq Jaffer
edf0075888
Add [@poll error] attribute (#10462) 2021-11-09 09:56:29 +00:00
Gabriel Scherer
1daea333b6 [refactoring] move Simplif.exact_application to Lambda
We need to use this logic in lambda/tmc.ml to support tupled functions.
2021-11-02 15:42:55 +01:00
Frédéric Bour
a84b25b222 prepare for TMC (tail modulo cons) transformation 2021-11-02 15:42:55 +01:00
Tom Kelly
7cffbd64a0 remove multicore nop debugging (reverts ocaml-multicore#384) 2021-10-08 15:31:53 +01:00
Tom Kelly
23852f7800 Merge commit 'cdc32182aed4ab327084aeb3090e529f6cec4b46' into 5.00 2021-10-04 13:16:04 +01:00
Tom Kelly
0ffeac19d7 Merge commit '1037341d8cbd533209c2898e0743757189ce8f1e' into parallel_minor_gc_4_13 2021-10-01 15:54:48 +01:00
Tom Kelly
d85f4d8efd Merge commit '099b86a046e304fe15e2bb37557bffc6aafaab15' into parallel_minor_gc_4_13 2021-10-01 12:19:35 +01:00
Tom Kelly
67e3095546 Merge commit 'd0f80077066105e1429ef8728b8362b8d698e298' into parallel_minor_gc_4_13 2021-09-29 15:16:38 +01:00
Sadiq Jaffer
1290ad7f93 add polling at mach layer 2021-09-06 15:25:08 +01:00
Gabriel Scherer
ff86950c25 [minor] make Lambda.Not_simple local to its only user 2021-07-15 22:12:56 +02:00
KC Sivaramakrishnan
34540fd116 Add primitive for fetching dls state 2021-06-10 17:02:29 +05:30
Vincent Laviron
dc08b85b16 Remove primitives Pdirapply and Prevapply 2021-05-25 18:21:31 +02:00
Vincent Laviron
2bc428664f Remove the Pidentity primitive 2021-05-25 18:18:50 +02:00
Antal Spector-Zabusky
e87be39194 Maintain more structural information in type-checking errors
This commit refactors the types that make up type-checking errors to
maintain more structural information.  Most significantly, we split
out the errors we get from unification, moregen, and type equality in
`Ctype` into three distinct exceptions, and retain the sorts of
information we keep during unification in the other two cases as well
(no more `Unify []`).  We also maintain more information in
`Includecore` about mismatches of primitives, manifests, and private
objects and variants

This commit doesn't make a lot of changes to the user-visible error
messages yet, only what's necessary to support the type changes, but
it enables a forthcoming patch where we use this improvement to
produce more informative error messages.

This commit includes existing work by Mekhrubon Tuarev, who did all
the early development.  I (Antal Spector-Zabusky) came and built the
layer of types on top.
2021-05-06 20:46:01 -04:00
Tom Kelly
aceef8b97c Merge commit '426b10c6a8497dfa0af6858075828c24e2d9570b' into parallel_minor_gc_4_12 2021-03-09 13:28:38 +00:00
Tom Kelly
79d5f2f1f2 Merge commit '06162616426d8689f868ec9b150c6b6a9ba7fdb9' into parallel_minor_gc_4_12 2021-03-04 13:42:33 +00:00
Tom Kelly
86fbc7e8d5 Merge commit 'b7509ca82f9bd647c1cb7e810b6bb152e145e3fb' into parallel_minor_gc_4_12 2021-03-03 15:28:59 +00:00
Tom Kelly
701bbb9b00 Merge commit 'e717512a54349bce4bbbb9590d4fe5a2c671c4e9' into parallel_minor_gc_4_12 2021-03-03 13:30:53 +00:00
Tom Kelly
29f4177a4e Merge commit '0ca651b95cbda5d58f7760f0fa1dba965d1f0828' into parallel_minor_gc_4_12 2021-03-02 16:15:55 +00:00
Tom Kelly
b84f29718a Merge commit '8f85e002b2e1f3f4ccf8fefa5ad9a137109168d1' into parallel_minor_gc_4_12 2021-03-01 21:57:28 +00:00