Skip to content

Commit 70073c6

Browse files
cknittclaude
andcommitted
Drop the name list from the untagged variants spec
Why: Payloads are now recognized only by annotations and builtin types, so the spec's list of stdlib type names and the fallback to it are gone. Rule 4 lists `promise<_>` as the one builtin class and says that a type is never recognized by its name; rule 5 keeps the stdlib's annotations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 8e295f9 commit 70073c6

1 file changed

Lines changed: 19 additions & 32 deletions

File tree

‎compiler/ml/UntaggedVariants.md‎

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -90,29 +90,31 @@ into one kind:
9090
| a function type | function | `typeof x === "function"` |
9191
| a record (not `@unboxed`), an inline record, `dict<_>` | object | `typeof x === "object"` |
9292
| `array<_>`, a tuple | instance `Array` | `Array.isArray(x)` |
93-
| a type declared with `@instanceOf("C")`, or listed in rule 5 | instance `C` | `x instanceof C` |
93+
| a type declared with `@instanceOf("C")` (rule 5) | instance `C` | `x instanceof C` |
94+
| `promise<_>` | instance `Promise` | `x instanceof Promise` |
9495
| a type declared with `@typeOf("k")` | kind `k` | `typeof x === "k"` |
9596
| anything else: an abstract type, a type variable, a variant, `list<_>`, an `@unboxed` record | unknown | no check |
9697

9798
The annotations of rule 5 are read first, on the type as written and on each
98-
type it abbreviates. Then the list of rule 5 is consulted on the type as
99-
written, and then the payload type is classified after expanding
100-
abbreviations (`type myDate = Date.t` is an instance case). `@typeOf("number")`
99+
type it abbreviates. Otherwise the payload type is classified after expanding
100+
abbreviations: `type ints = array<int>` is an array case, and `type name =
101+
string` a string case. A type is never recognized by its name. `@typeOf("number")`
101102
is the number kind, and `@typeOf("symbol")` is a kind of its own, with no
102103
builtin payload type. `@notUndefined` on an abstract type leaves it unknown.
103104

104105
- Implementation: `variant_layout.ml:get_block_type_from_typ`,
105-
`get_block_type`, `declared_block_type`;
106-
`ast_untagged_variants.ml:type_is_builtin_object`.
106+
`get_block_type`, `declared_block_type`.
107107
- Tests: `spec_test` rules 4 (`kinds`, `tuples`, `aliasDict`, `instances`,
108108
`unknown`); fixtures `UntaggedConstructorMoreThanOneArg.res`,
109109
`UntaggedConstructorAttributeMoreThanOneArg.res`, `UntaggedNonUnary1.res`,
110110
`UntaggedNonUnary2.res` ("Constructor A has more than one argument."),
111-
`UntaggedUnknown.res` (`list<float>` is unknown);
112-
`tests/tests/src/untagged_runtime_annotations_test.res`.
111+
`UntaggedUnknown.res` (`list<float>` is unknown),
112+
`untagged_unannotated_stdlib_name.res` (a type named like a stdlib class
113+
is unknown); `tests/tests/src/untagged_runtime_annotations_test.res`,
114+
`untagged_builtin_alias_test.res`.
113115
- Shaped by #6121, #6208, #6219, #6279, #6368, #6394, #6550, #6670.
114116

115-
### 5. Declared and listed instance types
117+
### 5. Declared instance types
116118

117119
`@instanceOf("C")` on a type declares that its values are instances of the
118120
global class at the path `C`, such as `"Date"` or `"Intl.Locale"`.
@@ -181,37 +183,22 @@ The stdlib annotates the types of the classes it binds:
181183
| `Int8Array.t` and the other typed arrays, public abbreviations of `TypedArray.t<_>` | `@instanceOf` the class of the same name |
182184
| `Symbol.t` | `@typeOf("symbol")` |
183185

184-
Types without annotations are recognized from a fixed list of type names in
185-
`ast_untagged_variants.ml:type_to_instanceof_backed_obj`. Every listed stdlib
186-
type is annotated, so the list only covers other types printed with one of
187-
these paths. The predefined
188-
`promise<_>` and `array<_>` are matched by path; the others by the printed
189-
path of the type:
190-
191-
| Type | Class |
192-
| --- | --- |
193-
| `promise<_>` | `Promise` |
194-
| `array<_>` | `Array` (checked with `Array.isArray`) |
195-
| `Date.t`, `RegExp.t`, `File.t`, `Blob.t`, `ArrayBuffer.t`, `DataView.t` | the class of the same name |
196-
| `Set.t`, `Map.t`, `WeakSet.t`, `WeakMap.t` | the class of the same name |
197-
| `Int8Array.t`, `Uint8Array.t`, `Uint8ClampedArray.t`, `Int16Array.t`, `Uint16Array.t`, `Int32Array.t`, `Uint32Array.t`, `Float32Array.t`, `Float64Array.t`, `BigInt64Array.t`, `BigUint64Array.t` | the class of the same name |
198-
199-
The listed classes have no superclasses. The typed-array types are
200-
abbreviations of one type, `TypedArray.t<_>`, and are told apart only by
201-
their annotations, which are read on the name as written (Known bugs).
186+
The typed-array types are abbreviations of one type, `TypedArray.t<_>`, and
187+
are told apart only by their annotations, which are read on the name as
188+
written (Known bugs).
202189

203190
- Implementation: `variant_layout.ml:runtime_annotations`,
204191
`declared_block_type`, `check_manifest_annotation`;
205192
`ast_untagged_variants.ml:process_runtime_annotation`, `unsupported_class`,
206-
`check_runtime_annotation`,
207-
`type_to_instanceof_backed_obj`;
193+
`check_runtime_annotation`;
208194
`variant_runtime.ml:Instance`; `js_exp_make.ml:class_constructor`.
209195
- Tests: `spec_test` rules 4 and 5;
210196
`tests/tests/src/untagged_runtime_annotations_test.res`,
211197
`untagged_runtime_annotations_shadow_test.res`,
212198
`untagged_file_blob_test.res`; the fixtures above,
213199
`UntaggedAtMostOneInstance.res`, `UntaggedTupleAndArray.res`.
214-
- Shaped by #6296, #6383, #6396, #7788, #8009, #8950, #8948. Related: #7147.
200+
- Shaped by #6296, #6383, #6396, #7788, #8009, #8950, #8948, #8949.
201+
Related: #7147.
215202

216203
### 6. Well-formedness
217204

@@ -537,8 +524,8 @@ had to answer, and the answers of rule 5:
537524
7. **Implied `@notUndefined`.** A declared class or kind implies it, and
538525
rule 5 rejects annotations on abbreviations of types that can hold
539526
`undefined`.
540-
8. **Abbreviations.** Annotations are read along the chain of abbreviations;
541-
the list of rule 5 is still read on the name as written.
527+
8. **Abbreviations.** Annotations are read along the chain of abbreviations,
528+
and a type is never recognized by its name.
542529
9. **Globals.** A shadowed class is read through `globalThis`. A missing
543530
class throws when the check runs (rule 10).
544531

0 commit comments

Comments
 (0)