From 051e4ccf674588f3b316ddf1323bdf396fd48719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Wed, 27 Aug 2025 11:46:49 +0200 Subject: [PATCH 1/4] Revert "Runtime: fix annotation of caml_compare" This reverts commit 3ceafdf42b62c96225f0d482fa29ca0f1ab589f9: `caml_compare` can raise `Invalid_argument`. --- runtime/js/compare.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/js/compare.js b/runtime/js/compare.js index 7ccde88b71..0aa1289d93 100644 --- a/runtime/js/compare.js +++ b/runtime/js/compare.js @@ -251,7 +251,7 @@ function caml_compare_val(a, b, total) { b = b[i]; } } -//Provides: caml_compare mutable (const, const) +//Provides: caml_compare (const, const) //Requires: caml_compare_val function caml_compare(a, b) { return caml_compare_val(a, b, true); From d80abb0e914109786d3efdf8806933b9633b44ae Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Wed, 27 Aug 2025 14:42:39 +0200 Subject: [PATCH 2/4] Fix runtime annotations Some comparison functions may raise on functional values. --- runtime/js/compare.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/runtime/js/compare.js b/runtime/js/compare.js index 0aa1289d93..aba227499e 100644 --- a/runtime/js/compare.js +++ b/runtime/js/compare.js @@ -251,6 +251,8 @@ function caml_compare_val(a, b, total) { b = b[i]; } } + +// May raise //Provides: caml_compare (const, const) //Requires: caml_compare_val function caml_compare(a, b) { @@ -265,32 +267,44 @@ function caml_int_compare(a, b) { if (a === b) return 0; return 1; } -//Provides: caml_equal mutable (const, const) + +// May raise +//Provides: caml_equal (const, const) //Requires: caml_compare_val function caml_equal(x, y) { return +(caml_compare_val(x, y, false) === 0); } -//Provides: caml_notequal mutable (const, const) + +// May raise +//Provides: caml_notequal (const, const) //Requires: caml_compare_val function caml_notequal(x, y) { return +(caml_compare_val(x, y, false) !== 0); } -//Provides: caml_greaterequal mutable (const, const) + +// May raise +//Provides: caml_greaterequal (const, const) //Requires: caml_compare_val function caml_greaterequal(x, y) { return +(caml_compare_val(x, y, false) >= 0); } -//Provides: caml_greaterthan mutable (const, const) + +// May raise +//Provides: caml_greaterthan (const, const) //Requires: caml_compare_val function caml_greaterthan(x, y) { return +(caml_compare_val(x, y, false) > 0); } -//Provides: caml_lessequal mutable (const, const) + +// May raise +//Provides: caml_lessequal (const, const) //Requires: caml_compare_val function caml_lessequal(x, y) { return +(caml_compare_val(x, y, false) <= 0); } -//Provides: caml_lessthan mutable (const, const) + +// May raise +//Provides: caml_lessthan (const, const) //Requires: caml_compare_val function caml_lessthan(x, y) { return +(caml_compare_val(x, y, false) < 0); From 9c81d825cf89a9b7ffe760cf3336000ef9f01db0 Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Wed, 27 Aug 2025 18:40:07 +0200 Subject: [PATCH 3/4] Update changelog --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 8b7eb42da0..756c51cd58 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## Features/Changes * Compiler/wasm: omit code pointer from closures when not used (#2059) +* Compiler: fix purity of comparison functions (again) (#2092) # 6.2.0 (2025-07-30) - Lille From 1d97ccb1c38d97f55533cd8dfdfcc07099186fb0 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 28 Aug 2025 08:45:11 +0200 Subject: [PATCH 4/4] Tests: accept --- compiler/tests-full/stdlib.cma.expected.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/tests-full/stdlib.cma.expected.js b/compiler/tests-full/stdlib.cma.expected.js index 6fd214a2e7..b655d5d72f 100644 --- a/compiler/tests-full/stdlib.cma.expected.js +++ b/compiler/tests-full/stdlib.cma.expected.js @@ -350,7 +350,7 @@ //# unitInfo: Provides: Stdlib //# unitInfo: Requires: CamlinternalFormatBasics -//# shape: Stdlib:[F(1),F(1),N,N,N,N,N,N,N,N,N,N,N,N,N,F(2)*,F(2)*,F(1)*,N,N,F(1)*,N,N,N,N,N,N,F(2)*,F(1),F(1)*,F(1)*,F(1),F(1)*,F(1),F(1),F(1),F(2),N,N,N,F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(3),F(1),F(1),F(2),F(2),F(2),F(4),F(4),F(2),F(2),F(2),F(2),F(1),F(1),F(1),F(1),F(2),F(1),F(1),F(3),F(1),F(1),F(4),F(4),F(2),F(1),F(1),F(1),F(2),F(1),F(1),F(1),F(1),F(2),N,F(1)*,F(2),F(1),F(1),F(1),F(4),F(1),N] +//# shape: Stdlib:[F(1),F(1),N,N,N,N,N,N,N,N,N,N,N,N,N,F(2),F(2),F(1)*,N,N,F(1)*,N,N,N,N,N,N,F(2)*,F(1),F(1)*,F(1)*,F(1),F(1)*,F(1),F(1),F(1),F(2),N,N,N,F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(1),F(3),F(1),F(1),F(2),F(2),F(2),F(4),F(4),F(2),F(2),F(2),F(2),F(1),F(1),F(1),F(1),F(2),F(1),F(1),F(3),F(1),F(1),F(4),F(4),F(2),F(1),F(1),F(1),F(2),F(1),F(1),F(1),F(1),F(2),N,F(1)*,F(2),F(1),F(1),F(1),F(4),F(1),N] (function (globalThis){ "use strict"; @@ -9077,7 +9077,7 @@ //# unitInfo: Provides: Stdlib__Int32 //# unitInfo: Requires: Stdlib, Stdlib__Sys -//# shape: Stdlib__Int32:[N,N,N,F(2),F(2),F(1)*,F(1)*,F(1)*,N,N,F(1)*,F(1)*,F(1),F(1)*,F(2)*,F(2)*,F(2)*,F(2)*,F(2)*,F(2)*,F(1)*] +//# shape: Stdlib__Int32:[N,N,N,F(2),F(2),F(1)*,F(1)*,F(1),N,N,F(1)*,F(1),F(1),F(1)*,F(2)*,F(2)*,F(2),F(2),F(2),F(2)*,F(1)*] (function (globalThis){ "use strict"; @@ -9213,7 +9213,7 @@ //# unitInfo: Provides: Stdlib__Int64 //# unitInfo: Requires: Stdlib -//# shape: Stdlib__Int64:[N,N,N,F(2),F(2),F(1)*,F(1)*,F(1)*,N,N,F(1)*,F(1)*,F(1),F(1)*,F(2)*,F(2)*,F(2)*,F(2)*,F(2)*,F(2)*,F(1)*] +//# shape: Stdlib__Int64:[N,N,N,F(2),F(2),F(1)*,F(1)*,F(1),N,N,F(1)*,F(1),F(1),F(1)*,F(2)*,F(2)*,F(2),F(2),F(2),F(2)*,F(1)*] (function (globalThis){ "use strict"; @@ -9362,7 +9362,7 @@ //# unitInfo: Provides: Stdlib__Nativeint //# unitInfo: Requires: Stdlib, Stdlib__Sys -//# shape: Stdlib__Nativeint:[N,N,N,F(2),F(2),F(1)*,F(1)*,F(1)*,N,N,N,F(1)*,F(1)*,F(1),F(1)*,F(2)*,F(2)*,F(2)*,F(2)*,F(2)*,F(2)*,F(1)*] +//# shape: Stdlib__Nativeint:[N,N,N,F(2),F(2),F(1)*,F(1)*,F(1),N,N,N,F(1)*,F(1),F(1),F(1)*,F(2)*,F(2)*,F(2)*,F(2),F(2),F(2)*,F(1)*] (function (globalThis){ "use strict";