Semantic Diff

#9050 Make typed arrays distinct types

3 commits

eb08738214b8f67f69d1f33c38c70e097dd1194c..pr-9050

0839518f3 · cknitt + Claude · Oct 26, 2026, 06:36 UTC

Make typed arrays private abbreviations of TypedArray.t

Why

Every typed array type was a public abbreviation of TypedArray.t<_>, so the type checker took Uint8Array.t for Int8Array.t, while an untagged variant recognized them by their classes: I8(uint8Array) type-checked and then matched the U8 case (#8955).

Each typed array type is private TypedArray.t<_>: a distinct type that upcasts to TypedArray.t<_> with :>. The TypedArray.Impl functor gives each typed array module the functions of TypedArray for its own type, with their documentation, so Int8Array.get works on an Int8Array.t and Int8Array.slice returns one. The functor holds only externals, so including it emits no code; Stdlib_TypedArray gains an empty Impl function.

Typing rules changed (typed arrays):

@unboxed type ta = I8(Int8Array.t) | U8(Uint8Array.t)let x = I8(Uint8Array.fromArray([1]))
rule
Before Int8Array.t and Uint8Array.t are both TypedArray.t<int>,
so I8(uint8Array) type-checks and is matched as U8 at run time
After
they are distinct types; I8(uint8Array) is a type error

addedDiagnostic one typed array for another

let x = I8(Uint8Array.fromArray([1]))
diagnostic
Before
After
none This has type: Uint8Array.tBut it's expected to have type: Int8Array.t
eb665272c · cknitt + Claude · Oct 26, 2026, 06:36 UTC

Require a private abbreviation for a class on an abstract type

Why

A class declared with @instanceOf on a public abbreviation of an abstract type made every value of that type an instance, and two such abbreviations could declare the same values instances of two classes while the type checker treated them as one type, as the typed arrays did.

Typedecl.check_manifest_annotation rejects @instanceOf on a public abbreviation of a type the compiler does not see; a subclass already had to be private.

Typing rules changed (a class on an abbreviation):

type node@instanceOf("Element") type element = node
rule
Before a class on a public abbreviation of an abstract type is
accepted
After the abbreviation must be private,
@instanceOf("Element") type element = private node

addedDiagnostic a class on a public abbreviation

type node@instanceOf("Element") type element = node
diagnostic
Before
After
none A class must be declared on an abstract type or a private abbreviation:write `= private ...`, so that values of the abbreviated type are notinstances of Element without a coercion, and another abbreviation cannotdeclare them instances of another class.
53a463ee6 · cknitt + Claude · Oct 26, 2026, 06:52 UTC

Migrate the deprecated TypedArray functions on a TypedArray.t

Why

The migration test applied the deprecated TypedArray.*ToEnd functions to a Uint8Array.t, which is now a type of its own; those functions exist only on TypedArray.

The test's typed array is upcast to TypedArray.t<int>.