A type is named in a type section, or written in place where a value’s type stands. Records, sets, enumerations and the other modelling types are declared by name; arrays, spans, vectors, matrices and tensors may also be written in place.
type-denoter
type-denoter = [ "packed" ] ( record-type | array-type ) | set-type | bitset-type | bitrecord-type | file-type
| enumeration-type | subrange-type | wide-integer-type | error-domain-type | span-type | tensor-type
| dynamic-tensor-type | device-scalar-type | (?! "tensor" "of" ) type-reference .The right side of a type declaration.
packedqualifies a record or an array only.
A type named
tensortakes no type arguments here:tensor ofwould begin a tensor without its rank, which is refused.
Used in type-declaration.
record-type
record-type = "record" { field-group } "end" .A record: fields of named types.
Used in type-denoter.
field-group
field-group = identifier { "," identifier } ":" value-type ";" .Fields of one type.
Used in record-type.
array-type
array-type = "array" { dimension-group } "of" type-reference .An array with one or more groups of dimensions, or with none: an owned dynamic array.
The element is a named type; an array or tensor written in place cannot be an element.
Used in type-denoter, shape-form.
dimension-group
dimension-group = "[" dimension { "," dimension } "]" .Dimensions in brackets.
Used in array-type.
dimension
dimension = identifier | expression ".." expression .A dimension: an ordinal type by its name, or the bounds low..high.
Used in dimension-group.
span-type
span-type = "span" "of" type-name .A read-only window over contiguous elements.
Used in type-denoter, shape-form.
set-type
set-type = "set" "of" type-name .A set of an ordinal type.
Used in type-denoter.
file-type
file-type = "file" "of" type-reference .A file of fixed-size records.
Used in type-denoter.
subrange-type
subrange-type = ( (?= integer-literal | "+" | "-" | unicode-literal ) expression | identifier ) ".." expression .The values from a low bound to a high one.
The low bound opens with a number, a sign or a character, or is one name.
Used in type-denoter.
enumeration-type
enumeration-type = "(" enumeration-literal { "," enumeration-literal } ")" .An enumeration, or a sum type whose cases carry fields.
Used in type-denoter.
enumeration-literal
enumeration-literal = identifier [ "(" [ sum-field { "," sum-field } ] ")" ] .A case of an enumeration, with its fields in parentheses when it carries any.
An empty field set is refused when the program is analysed: a case without fields is written by its name alone.
Used in enumeration-type.
sum-field
sum-field = identifier ":" ( shape-form | (?! "tensor" "of" ) qualified-type-reference ) .A field of a sum type’s case.
A type named
tensortakes no type arguments here:tensor ofwould begin a tensor without its rank, which is refused.
Used in enumeration-literal.
bitset-type
bitset-type = "bitset" "[" expression "]" .A fixed number of bits.
Used in type-denoter.
bitrecord-type
bitrecord-type = "bitrecord" "[" expression "]" { bitrecord-field-group } "end" .Bit fields laid out from the least significant bit, as a device register is.
Used in type-denoter.
bitrecord-field-group
bitrecord-field-group = identifier ":" type-name [ access-mode ] [ "at" expression ] ";"
| identifier "," identifier { "," identifier } ":" type-name [ access-mode ] ";" .Fields of one type, with the direction the program may use them in, and for one field the offset it must land at.
Used in bitrecord-type.
access-mode
access-mode = "readonly" | "writeclear" .A field the program only reads, or one it only writes to clear.
Used in bitrecord-field-group.
wide-integer-type
wide-integer-type = ( "int" | "uint" ) "[" expression "]" .A signed or unsigned integer of a given width beyond 64 bits.
Used in type-denoter.
error-domain-type
error-domain-type = "error" "(" identifier { "," identifier } ")" .The codes a routine can fail with.
Used in type-denoter.
tensor-type
tensor-type = ( "vector" "[" expression "]" | "matrix" "[" expression "," expression "]"
| "tensor" "[" expression { "," expression } "]" ) "of" type-reference [ "on" "gpu" ] .A vector of a length, a matrix of rows and columns, or a tensor of any rank, optionally placed on the GPU.
Used in type-denoter, pointer-tensor-type, shape-form.
dynamic-tensor-type
dynamic-tensor-type = ( "vector" | "matrix" ) "of" type-reference .A vector or a matrix whose lengths the value carries.
tensor ofis refused: a rank must be written. Where a vector, a matrix or a tensor may be written in place, a type namedtensortakes no type arguments, sincetensor ofwould begin one without its rank.
Used in type-denoter, shape-form.
device-scalar-type
device-scalar-type = identifier "on" "gpu" .A single value placed on the GPU.
Used in type-denoter, shape-form.
pointer-tensor-type
pointer-tensor-type = "pointer" tensor-type .A pointer that lends a tensor written in place, as a parameter.
Used in parameter-type.
shape-form
shape-form = array-type | span-type | tensor-type | dynamic-tensor-type | device-scalar-type .The types that may be written in place of a type’s name.
Used in result-type, sum-field, value-type, allocation.
value-type
value-type = [ "tracked" (?= identifier | "array" ) ]
( shape-form | stream-type | (?! "tensor" "of" ) type-reference ) .The type of a variable, a field or a parameter; tracked pairs the value with the gradient tape.
trackedpairs the type with the gradient tape only before a type’s name orarray; anywhere else it is the name of a type. A type namedtensortakes no type arguments here:tensor ofwould begin a tensor without its rank, which is refused.
Used in variable-group, parameter-type, field-group.
stream-type
stream-type = "stream" type-arguments [ fails-clause ] .A stream of elements, optionally failing with an error domain.
Used in value-type.
type-reference
type-reference = [ [ "borrowed" | "owning" ] "pointer" ] type-name .A type by its name, or a pointer to one; borrowed and owning say whether the pointer owns what it points to.
Used in generator-heading, result-type, type-denoter, array-type, file-type, tensor-type, dynamic-tensor-type, value-type.
qualified-type-reference
qualified-type-reference = [ [ "borrowed" | "owning" ] "pointer" ] identifier [ "." identifier ] [ type-arguments ] .A type reference whose name may be qualified by a namespace.
Used in sum-field.
type-name
type-name = identifier [ type-arguments ] .A type’s name, with the type arguments of a generic type.
Used in conformant-schema, fails-clause, span-type, set-type, bitrecord-field-group, type-reference, type-argument, allocation.
type-arguments
type-arguments = "of" ( type-argument | "(" type-argument { "," type-argument } ")" ) .One type argument, or several in parentheses.
Used in stream-type, qualified-type-reference, type-name, scheduled-stream, schedule-statement, function-call.
type-argument
type-argument = type-name | integer-literal .A type, or a whole number for a value parameter.
Used in type-arguments.