You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aff4439
Browse filesBrowse the repository at this point in the historyBrowse files
* 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):
Example:
@unboxed type ta = I8(Int8Array.t) | U8(Uint8Array.t)
let x = I8(Uint8Array.fromArray([1]))
Before (rule): `Int8Array.t` and `Uint8Array.t` are both `TypedArray.t<int>`,
so `I8(uint8Array)` type-checks and is matched as `U8` at run time
After (rule): they are distinct types; `I8(uint8Array)` is a type error
Diagnostic added (one typed array for another):
Example:
let x = I8(Uint8Array.fromArray([1]))
Before (diagnostic): none
After (diagnostic):
This has type: Uint8Array.t
But it's expected to have type: Int8Array.t
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
* 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):
Example:
type node
@instanceof("Element") type element = node
Before (rule): a class on a public abbreviation of an abstract type is
accepted
After (rule): the abbreviation must be private,
`@instanceOf("Element") type element = private node`
Diagnostic added (a class on a public abbreviation):
Example:
type node
@instanceof("Element") type element = node
Before (diagnostic): none
After (diagnostic):
A class must be declared on an abstract type or a private abbreviation:
write `= private ...`, so that values of the abbreviated type are not
instances of Element without a coercion, and another abbreviation cannot
declare them instances of another class.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
* 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>`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
---------
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Typed arrays are distinct types: `Int8Array.t` and the others are private abbreviations of `TypedArray.t<_>`, so an untagged variant can no longer take one typed array for another. Use each module's own functions, such as `Int8Array.get`, or upcast with `(view :> TypedArray.t<int>)` to call the `TypedArray` functions.
2
+
-`@instanceOf` that introduces a class on an abbreviation of an abstract type requires a private abbreviation: write `@instanceOf("Element") type element = private node`.
Copy file name to clipboardExpand all lines: compiler/ml/UntaggedVariants.md
+12-1Lines changed: 12 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -181,13 +181,24 @@ type hierarchy (`type dogLike<'a> = private animalLike<_dog<'a>>`). A public
181
181
would `type dog = animal<int>` or `type dog = phantom<int>` with
182
182
`type phantom<'a> = animal`.
183
183
184
+
A class introduced on an abbreviation of a type the compiler does not see is
185
+
private too: `@instanceOf("Element") type element = private node`. A public
186
+
abbreviation would make every `node` an `element`, and a second one could
187
+
declare the same values instances of another class while the type checker
188
+
treats both as one type. The stdlib's typed arrays are such private
189
+
abbreviations of `TypedArray.t<_>`, so `Int8Array.t` and `Uint8Array.t` are
190
+
different types, upcast to `TypedArray.t<int>` with `:>`. Each typed array
191
+
module has the functions of `TypedArray` for its own type, through the
192
+
`TypedArray.Impl` functor.
193
+
184
194
| Declaration | Error | Fixture |
185
195
| --- | --- | --- |
186
196
|`@typeOf("string") type t = option<string>`, `type t<'a> = 'a`, an abbreviation of `unit`, `list<_>` or a variant |@typeOf on a type abbreviation must describe an abstract type, ... |`runtime_annotation_on_option.res`, `runtime_annotation_on_type_variable.res`|
187
197
|`@notUndefined type t = option<int>`|@notUndefined on a type abbreviation must describe an abstract type, ... |`not_undefined_on_option.res`, `tests/build_tests/not_undefined_attribute`|
188
198
|`@typeOf("number") type t = sym` with `@typeOf("symbol") type sym`, `@typeOf("string") type t = int`, or an abbreviation of a function type, a record or a tuple | This annotation, @typeOf("number"), contradicts the abbreviated type, whose values are recognized by @typeOf("symbol"). An array or tuple is recognized by Array.isArray. |`runtime_annotation_contradicts_manifest.res`, `runtime_annotation_contradicts_builtin.res`, `runtime_annotation_contradicts_function.res`, `runtime_annotation_contradicts_tuple.res`|
189
199
|`@instanceOf("Date") type date = X.t` in a functor of `X`, or over `(type a)`; `@notUndefined type t = X.t`|@instanceOf cannot describe the type of a functor parameter, ... |`instance_of_functor_parameter.res`, `type_of_locally_abstract_type.res`, `not_undefined_on_functor_parameter_type.res`|
190
200
|`@instanceOf("Dog") type dog = animal`, `= animal<int>`, or `= phantom<int>` with `type phantom<'a> = animal`| A subclass must be a private abbreviation ... |`instance_of_public_subclass.res`, `instance_of_public_subclass_instance.res`, `instance_of_public_subclass_through_alias.res`|
201
+
|`@instanceOf("Element") type element = node` with `type node`| A class must be declared on an abstract type or a private abbreviation ... |`instance_of_public_abbreviation.res`; `typed_array_cases_distinct.res` (typed arrays are distinct types) |
191
202
|`@instanceOf("Animal") type t = private dog`| Animal appears twice in this chain of abbreviations ... |`instance_of_class_twice_in_chain.res`|
192
203
|`@instanceOf("MyList") type t = private array<int>`|@instanceOf("MyList") cannot describe the values of an array type: ... subclasses of Array are not supported. |`instance_of_array_subclass.res`|
193
204
| any of the three on a record or variant |@instanceOf can only be used on abstract types and type abbreviations ... |`runtime_annotation_on_record.res`, `invalid_attribute_not_undefined.res`|
Copy file name to clipboardExpand all lines: packages/@rescript/runtime/Stdlib_BigInt64Array.res
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,12 @@
1
1
/** The `BigInt64Array` typed array represents an array of 64-bit signed integers in platform byte order. See [BigInt64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array)
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
Copy file name to clipboardExpand all lines: packages/@rescript/runtime/Stdlib_BigUint64Array.res
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,12 @@
1
1
/** The `BigUint64Array` typed array represents an array of 64-bit unsigned integers in platform byte order. See [BigUint64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array)
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
Copy file name to clipboardExpand all lines: packages/@rescript/runtime/Stdlib_Float32Array.res
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,12 @@
1
1
/** The `Float32Array` typed array represents an array of 32-bit floating point numbers in platform byte order. See [Float32Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
Copy file name to clipboardExpand all lines: packages/@rescript/runtime/Stdlib_Float64Array.res
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,12 @@
1
1
/** The `Float64Array` typed array represents an array of 64-bit floating point numbers in platform byte order. See [Float64Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array)
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
Copy file name to clipboardExpand all lines: packages/@rescript/runtime/Stdlib_Int16Array.res
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,12 @@
1
1
/** The `Int16Array` typed array represents an array of twos-complement 16-bit signed integers in platform byte order. See [Int16Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array)
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
Copy file name to clipboardExpand all lines: packages/@rescript/runtime/Stdlib_Int32Array.res
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,12 @@
1
1
/** The `Int32Array` typed array represents an array of twos-complemenet 32-bit signed integers in platform byte order. See [Int32Array on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array)
/**`bytesPerElement` returns the element size. See [BYTES_PER_ELEMENT on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/BYTES_PER_ELEMENT)
0 commit comments