Skip to content

Expose {Int,Int32,Int64,Nativeint}.{min,max} #10389

@alainfrisch

Description

@alainfrisch

Stdlib.{min,max} are quite bad performance-wise (even when inlined, they will still call the polymorphic comparison C primitive). In #10251, I proposed to add compiler primitives to allow the optimizer generate better code when those functions are used on simple numerical types, but @xavierleroy's position (#10251 (comment)) is rather that these functions should eventually go away, and one should stop using them.

So, I believe we should:

  • Expose specialized versions of the functions in Int, Int32, Int64, Nativeint. For Char, Uchar and String, it's less obviously useful. For Bool, we already have || and &&, but it could still perhaps be useful (for the sake of uniformity, and also to avoid the short-circuit behavior?). For Float, the functions already exist (also with *_num variants); idem for Zarith`s Q and Z modules. Are people using those functions on non-numerical types?
  • Mark Stdlib.{min,max} as being deprecated, in order to help users spot the usually inefficient call sites, and prepare for a possible removal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions