[m-rev.] for post-commit review: move checked conversions to int to the library

Julien Fischer jfischer at opturion.com
Fri Mar 6 21:59:45 AEDT 2026


On Fri, 6 Mar 2026 at 20:32, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:

> For review by Julien, since he has this paged in. The only things
> worth looking at are the new comments on the moved predicates,
> and whether my evaluation of the relative performance of the
> old and new implementations of int64.to_int is correct.

I suspect it's much of a muchness.

> Move the to_int predicates into the standard library
>
> tests/hard_coded/truncate_to_int.m:
>     Delete the {int64,uint64,uint32}_to_int predicates, and ...
>
> library/int64.m:
> library/uint32.m:
> library/uint64.m:
>     ... move them to these modules, where they always were intended to go.
>     Add proper comments describing them.
>
>     In the case of int64.m, it already had a to_int predicate doing a checked
>     conversion. Replace its definition with the one from truncate_to_int.m,
>     because it should never be slower, and should be faster on some platforms.
>
>     Add det function versions of the new predicates, which abort
>     instead of failing.
>
> NEWS.md:
>     Announce the new predicates.

...

> diff --git a/library/int64.m b/library/int64.m
> index e7e26c692..c2b3dc0f3 100644
> --- a/library/int64.m
> +++ b/library/int64.m
> @@ -53,16 +53,20 @@
>
>      % to_int(I64, I):
>      %
> -    % Convert an int64 into an int.
> -    % Fail if I64 is not in the range [int.min_int, int.max_int].
> +    % Convert an int64 to a mathematically equivalent int.
> +    %
> +    % If ints are 64 bits, always succeed, since the two types
> +    % are effectively identical.
> +    %
> +    % If ints are 32 bits, succeed only if I64 is in the range
> +    % [int.min_int, int.max_int], meaning [2^31, 2^31 - 1].

The lower end of that range should be -2^31.

The rest looks fine.

Julien.


More information about the reviews mailing list