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-denotertype-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 .packedrecord-typerecord-typearray-typearray-typeset-typeset-typebitset-typebitset-typebitrecord-typebitrecord-typefile-typefile-typeenumeration-typeenumeration-typesubrange-typesubrange-typewide-integer-typewide-integer-typeerror-domain-typeerror-domain-typespan-typespan-typetensor-typetensor-typedynamic-tensor-typedynamic-tensor-typedevice-scalar-typedevice-scalar-typenot followed by "tensor" "of"type-referencetype-reference
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.

packed qualifies a record or an array only.

A type named tensor takes no type arguments here: tensor of would begin a tensor without its rank, which is refused.

Used in type-declaration.

record-type

record-typerecord-type = "record" { field-group } "end" .recordfield-groupfield-groupend
record-type = "record" { field-group } "end" .

A record: fields of named types.

Used in type-denoter.

field-group

field-groupfield-group = identifier { "," identifier } ":" value-type ";" .identifieridentifier,identifieridentifier:value-typevalue-type;
field-group = identifier { "," identifier } ":" value-type ";" .

Fields of one type.

Used in record-type.

array-type

array-typearray-type = "array" { dimension-group } "of" type-reference .arraydimension-groupdimension-groupoftype-referencetype-reference
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-groupdimension-group = "[" dimension { "," dimension } "]" .[dimensiondimension,dimensiondimension]
dimension-group = "[" dimension { "," dimension } "]" .

Dimensions in brackets.

Used in array-type.

dimension

dimensiondimension = identifier | expression ".." expression .identifieridentifierexpressionexpression..expressionexpression
dimension = identifier | expression ".." expression .

A dimension: an ordinal type by its name, or the bounds low..high.

Used in dimension-group.

span-type

span-typespan-type = "span" "of" type-name .spanoftype-nametype-name
span-type = "span" "of" type-name .

A read-only window over contiguous elements.

Used in type-denoter, shape-form.

set-type

set-typeset-type = "set" "of" type-name .setoftype-nametype-name
set-type = "set" "of" type-name .

A set of an ordinal type.

Used in type-denoter.

file-type

file-typefile-type = "file" "of" type-reference .fileoftype-referencetype-reference
file-type = "file" "of" type-reference .

A file of fixed-size records.

Used in type-denoter.

subrange-type

subrange-typesubrange-type = ( (?= integer-literal | "+" | "-" | unicode-literal ) expression | identifier ) ".." expression .followed by integer-literal | "+" | "-" | unicode-literalexpressionexpressionidentifieridentifier..expressionexpression
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-typeenumeration-type = "(" enumeration-literal { "," enumeration-literal } ")" .(enumeration-literalenumeration-literal,enumeration-literalenumeration-literal)
enumeration-type = "(" enumeration-literal { "," enumeration-literal } ")" .

An enumeration, or a sum type whose cases carry fields.

Used in type-denoter.

enumeration-literal

enumeration-literalenumeration-literal = identifier [ "(" [ sum-field { "," sum-field } ] ")" ] .identifieridentifier(sum-fieldsum-field,sum-fieldsum-field)
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-fieldsum-field = identifier ":" ( shape-form | (?! "tensor" "of" ) qualified-type-reference ) .identifieridentifier:shape-formshape-formnot followed by "tensor" "of"qualified-type-referencequalified-type-reference
sum-field = identifier ":" ( shape-form | (?! "tensor" "of" ) qualified-type-reference ) .

A field of a sum type’s case.

A type named tensor takes no type arguments here: tensor of would begin a tensor without its rank, which is refused.

Used in enumeration-literal.

bitset-type

bitset-typebitset-type = "bitset" "[" expression "]" .bitset[expressionexpression]
bitset-type = "bitset" "[" expression "]" .

A fixed number of bits.

Used in type-denoter.

bitrecord-type

bitrecord-typebitrecord-type = "bitrecord" "[" expression "]" { bitrecord-field-group } "end" .bitrecord[expressionexpression]bitrecord-field-groupbitrecord-field-groupend
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-groupbitrecord-field-group = identifier ":" type-name [ access-mode ] [ "at" expression ] ";" | identifier "," identifier { "," identifier } ":" type-name [ access-mode ] ";" .identifieridentifier:type-nametype-nameaccess-modeaccess-modeatexpressionexpression;identifieridentifier,identifieridentifier,identifieridentifier:type-nametype-nameaccess-modeaccess-mode;
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-modeaccess-mode = "readonly" | "writeclear" .readonlywriteclear
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-typewide-integer-type = ( "int" | "uint" ) "[" expression "]" .intuint[expressionexpression]
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-typeerror-domain-type = "error" "(" identifier { "," identifier } ")" .error(identifieridentifier,identifieridentifier)
error-domain-type = "error" "(" identifier { "," identifier } ")" .

The codes a routine can fail with.

Used in type-denoter.

tensor-type

tensor-typetensor-type = ( "vector" "[" expression "]" | "matrix" "[" expression "," expression "]" | "tensor" "[" expression { "," expression } "]" ) "of" type-reference [ "on" "gpu" ] .vector[expressionexpression]matrix[expressionexpression,expressionexpression]tensor[expressionexpression,expressionexpression]oftype-referencetype-referenceongpu
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-typedynamic-tensor-type = ( "vector" | "matrix" ) "of" type-reference .vectormatrixoftype-referencetype-reference
dynamic-tensor-type = ( "vector" | "matrix" ) "of" type-reference .

A vector or a matrix whose lengths the value carries.

tensor of is refused: a rank must be written. Where a vector, a matrix or a tensor may be written in place, a type named tensor takes no type arguments, since tensor of would begin one without its rank.

Used in type-denoter, shape-form.

device-scalar-type

device-scalar-typedevice-scalar-type = identifier "on" "gpu" .identifieridentifierongpu
device-scalar-type = identifier "on" "gpu" .

A single value placed on the GPU.

Used in type-denoter, shape-form.

pointer-tensor-type

pointer-tensor-typepointer-tensor-type = "pointer" tensor-type .pointertensor-typetensor-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-formshape-form = array-type | span-type | tensor-type | dynamic-tensor-type | device-scalar-type .array-typearray-typespan-typespan-typetensor-typetensor-typedynamic-tensor-typedynamic-tensor-typedevice-scalar-typedevice-scalar-type
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-typevalue-type = [ "tracked" (?= identifier | "array" ) ] ( shape-form | stream-type | (?! "tensor" "of" ) type-reference ) .trackedfollowed by identifier | "array"shape-formshape-formstream-typestream-typenot followed by "tensor" "of"type-referencetype-reference
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.

tracked pairs the type with the gradient tape only before a type’s name or array; anywhere else it is the name of a type. A type named tensor takes no type arguments here: tensor of would begin a tensor without its rank, which is refused.

Used in variable-group, parameter-type, field-group.

stream-type

stream-typestream-type = "stream" type-arguments [ fails-clause ] .streamtype-argumentstype-argumentsfails-clausefails-clause
stream-type = "stream" type-arguments [ fails-clause ] .

A stream of elements, optionally failing with an error domain.

Used in value-type.

type-reference

type-referencetype-reference = [ [ "borrowed" | "owning" ] "pointer" ] type-name .borrowedowningpointertype-nametype-name
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-referencequalified-type-reference = [ [ "borrowed" | "owning" ] "pointer" ] identifier [ "." identifier ] [ type-arguments ] .borrowedowningpointeridentifieridentifier.identifieridentifiertype-argumentstype-arguments
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-nametype-name = identifier [ type-arguments ] .identifieridentifiertype-argumentstype-arguments
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-argumentstype-arguments = "of" ( type-argument | "(" type-argument { "," type-argument } ")" ) .oftype-argumenttype-argument(type-argumenttype-argument,type-argumenttype-argument)
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-argumenttype-argument = type-name | integer-literal .type-nametype-nameinteger-literalinteger-literal
type-argument = type-name | integer-literal .

A type, or a whole number for a value parameter.

Used in type-arguments.