Ocaml_typing.ScalarThis module defines: The scalar types intrinsic to the OCaml compiler, and all of the primitive operations defined on them.
Overview: This module provides a comprehensive type system for scalar values in OCaml.
Type Hierarchy:
Representation Forms:
Operations:
The locality parameter tracks where boxed values are allocated.
A Scalar.t represents a particular OCaml type that represents a scalar value. It might be tagged, boxed, or neither. There is also a type parameter for the locality of the scalar value, which represents the location in which that boxed values are allocated.
The important consideration is for a Scalar.t to represent all of the argument and return types of all the primitives that we want to support. The submodules are organized to make it easy for use different subsets of scalars in different places. Some examples:
ignore_locality : _ t -> any_locality_mode t to convert arguments to any_locality_mode when defining primitives, e.g.: Icmp (Scalar.Integral.ignore_locality size, cmp)Intrinsic.Binary.Int_op.t for integer-only ops (Add, Sub, Mul, etc.)Intrinsic.Binary.Float_op.t for float-only opsIntrinsic.Binary.Three_way_compare of any_locality_mode t accepts any scalarvalue equivalents. This is supported by Maybe_naked.t:Value of 'a represents boxed/tagged valuesNaked of 'b represents unboxed/untagged values Example: Scalar.Maybe_naked.Value (Integral.Width.Taggable Int) vs Scalar.Maybe_naked.Naked (Integral.Width.Taggable Int)Intrinsic.Unary.Static_cast: Static_cast { src : any_locality_mode t; dst : 'mode t } which allows casting between different scalar types, e.g., from Int8 to Int32. See jane/doc/scalars.md for documentation on the semantics.In some cases, only the number of bits used in the container (e.g. a machine register or stack slot) is important. We use Width for this. Width.t always represents the width of a scalar layout -- it has exactly one constuctor for each bit-width of the corresponding scalar. The type parameter is irrelevant within the Width module, that's why it's usually fixed to any_locality_mode when the corresponding function is expecting a simple sum type (e.g., to_string).
val equal_any_locality_mode : any_locality_mode -> any_locality_mode -> boolmodule Maybe_naked : sig ... endval naked : 'a -> (_, 'a) Maybe_naked.tmodule type S := sig ... endmodule Integral : sig ... endmodule Floating : sig ... endmodule Width : sig ... endinclude S with type 'a width := 'a Width.ttype nonrec 'a t = ('a Width.t, any_locality_mode Width.t) Maybe_naked.tval all : any_locality_mode t listval ignore_locality : _ t -> any_locality_mode tval width : _ t -> any_locality_mode Width.tval to_string : any_locality_mode t -> stringval sort : any_locality_mode t -> Jkind_types.Sort.Const.tval integral : 'a Integral.t -> 'a tval floating : 'a Floating.t -> 'a tmodule Signedness : sig ... endmodule Integer_comparison : sig ... endmodule Float_comparison : sig ... endtype 'a scalar := 'a tmodule Operation : sig ... end