Skip to content

Types ​

Implementation status: core types Implemented; Int128 / UInt128 Phase 38; SIMD2/4/8/16<T> Phase 38+; Result<T, E> generic algebra Phase 21–23; BigInt Phase 46 MVP; some / any Phase 11–12; references &T / &mut T Partially implemented (SE-0461 default on, Phase 72)

In source code SYX types are written as type expressions (TypeExpr); the semantic layer maps them to TypeId.


Type Expression Forms ​

type-expr ::= named-type
            | optional-type
            | array-type
            | dict-type
            | function-type
            | tuple-type
            | reference-type
            | opaque-type
            | metatype

named-type      ::= identifier ('<' type-args '>')?
optional-type   ::= type '?'
array-type      ::= '[' type ']' | 'Array' '<' type '>'
dict-type       ::= '[' type ':' type ']' | 'Dictionary' '<' type ',' type '>'
function-type   ::= '(' type-list? ')' '->' type
tuple-type      ::= '(' type (',' type)+ ')'
reference-type  ::= '&' 'mut'? lifetime? type
opaque-type     ::= 'some' type | 'any' type
metatype        ::= 'Self' | 'SelfType' | 'Type'
FormExampleAST
Named typeInt, Array<Int>Named
OptionalString?, Int?Optional
Array[Int], Array<String>Array
Dictionary[String: Int]Dictionary
Function type(Int) -> StringFunction
Tuple type(Int, String)Tuple
Reference&Int, &mut StringReference
Opaquesome Equatable, any ProtocolOpaqueSome / OpaqueAny
MetatypeSelf, TypeMetatype
EmptyNo return valueVoid

Numeric Types ​

TypeSizeRangeStatus
Int88-bit signed-128 … 127Implemented
Int1616-bit signed-32,768 … 32,767Implemented
Int3232-bit signed-2³¹ … 2³¹-1Implemented
Int6464-bit signed-2⁶³ … 2⁶³-1Implemented
Int128128-bit signed-2¹²⁷ … 2¹²⁷-1Phase 38 GA
IntPlatform word size64-bit host → Int64; 32-bit → Int32Implemented
UInt88-bit unsigned0 … 255Implemented
UInt16 / UInt32 / UInt64Fixed-width unsignedImplemented
UInt128128-bit unsigned0 … 2¹²⁸-1Phase 38 GA
UIntPlatform word size, unsigned64-bit host → UInt64Implemented
Float32 / Float32-bit IEEE 754~1.4e-45 … ~3.4e38Implemented
Float64 / Double64-bit IEEE 754~4.9e-324 … ~1.8e308Implemented

Literal suffixes select a fixed width; unsuffixed integers default to Int and unsuffixed floats default to Double.

Basic Types ​

TypeDescriptionLiteral
BoolBooleantrue / false
StringUTF-8 string; grapheme-cluster semantics (Phase 84)"…"
VoidNo value returned—
CharacterSingle-scalar String type nameA single Character literal is a String
AnyAny type—

Collections and Dynamic Types ​

TypeLiteral exampleDescription
Array<T>[1, 2, 3]Ordered dynamic array (strongly typed, no bare Array)
Set<T>Set<Int>Deduplicating set
[K: V] / Dictionary<K, V>["a": 1]Static key-value type, keys must be Hashable
Object{ "k": "v" }Dynamic key-value object

Strong typing, Phase 60: the bare Array has been removed; Array<T> is required. Array<UInt8> is a byte stream.

Optional Types ​

T?  ::= Optional<T>
  • T? means nullable; only nil and T values are legal
  • Used together with ?? / ?. / !
swift
let a: Int? = 42
let b: Int? = nil
let c = a ?? 0                            // nil coalescing
let d = a?.description                    // optional chaining
let e = a!                                // force unwrap

Diagnostic: S004 type mismatch

The Result Type ​

Result<T, E> ::= ok(T) | err(E)
  • Result<Ok, Err> is used for error propagation
  • throws functions are tied to try / ? chains
  • Result<T, E> is a final class providing static ok / static err / isOk and more

Implementation status: Phase 21–23 builtin wire (GA); Phase 46+ provides class methods; see Language Guide: Enumerations.

BigInt ​

BigInt ::= <arbitrary precision integer>
  • Phase 46 MVP (__syx_bigint_* + Core)
  • BigInt.fromString(s) / b.toString() / BigInt.add(a, b)

Reference Types ​

&'a mut? T
swift
&Int           // Immutable borrow
&mut Int       // Mutable borrow
&'a Int        // With lifetime annotation (**Partially implemented**)
ItemDescription
Borrow checkingImplemented (borrow regions v8)
SE-0461On by default (Phase 72)
LifetimesPartially implemented (S017)
Borrows across awaitPartially implemented

Diagnostics: S011 borrow/mutation violation; S017 lifetime

Opaque Types and Existential Types ​

some P    -- Opaque result type (concrete at compile time; only P is known outside)
any P     -- Existential type (dynamic dispatch through a runtime witness table)
swift
func make() -> some Equatable { 42 }       // Int at compile time
let p: any CustomStringConvertible = "hi"   // Runtime witness
FormStatusMeaning
some PImplementedOpaque result (no virtual dispatch)
any PImplementedExistential type (witness table)
some P in parameter positionNot implementedPlanned

See Language Guide: Opaque Types.

Metatypes ​

swift
Self        // The current implementing type (class / struct / enum)
SelfType    // Same as Self (more explicit)
Type        // Metatype

Inside a protocol default implementation, Self refers to "the concrete type implementing this protocol".

SIMD Types ​

SIMD2<T> | SIMD4<T> | SIMD8<T> | SIMD16<T>
FormStatusBack end
SIMD2<T>ImplementedGeneric
SIMD4<T>ImplementedSSE / NEON
SIMD8<T>ImplementedAVX2
SIMD16<T>Phase 38+ partial GAAVX-512 / WASM SIMD128

The element T must be a fixed-width numeric type (Int8/16/32/64 / UInt8/16/32/64 / Float32/64).

See Language Guide: SIMD.

User-Defined Types ​

user-type ::= struct | class | data class | enum | actor | protocol
DeclarationRuntimeStatus
structValue/field aggregate MVPImplemented
classReference object (ARC)Implemented
data classData carrier + proof macrosPhase 50–52
final classSubclassing forbiddenPhase 60 GA
enumEnumeration with associated values (ADT)Implemented
actorIsolated concurrent objectImplemented
protocolProtocol type (witness)Implemented
extensionType extensionImplemented
global actorGlobal actorImplemented

Generic Type Parameters ​

generic-params ::= '<' identifier (',' identifier)* (':' constraint-list)? ('where' where-clause)? '>'
swift
struct Box<T> { var value: T }
func id<T>(x: T) -> T { return x }
enum Optional<T> { case some(T); case none }
  • Monomorphization generates concrete instances
  • Constraints: where T: Equatable / T: Comparable / T: CustomStringConvertible and more

See Generic Parameters and Arguments.

Type Inference ​

inference ::= bidirectional | unidirectional
  • When unannotated, types are inferred by semantic analysis
  • A let binding's type is frozen after its first assignment
  • A later incompatible assignment → S004
  • Contextual types (let arr: Array<Int> = [1, 2]) infer the element type backwards

Diagnostics: S004, S008 (narrowing)

Type Nesting ​

type-nesting ::= <not fully supported>
  • Top-level class / struct / enum: Implemented
  • Declaring one type nested inside another: Partially implemented (parser edge cases)
  • Outside visibility of nested types: incomplete
  • Prefer flat naming (OuterMarker_Inner)

See Language Guide: Nested Types.

Built-in Protocols (Implicit Conformance) ​

Numerics, Bool, String, Array<T>, Set<T>, Dictionary<K, V>, Object and others automatically conform to:

ProtocolDescription
Equatable==
HashableHashing
CustomStringConvertible.description()
CustomDebugStringConvertibleDebug description
Iteratorfunc next() -> String?
SequenceIterator factory

See Protocols and Conformances · crates/syx-stdlib/src/protocols.rs.

Type Aliases ​

typealias-decl ::= 'typealias' identifier '=' type
swift
typealias Handle = UInt64
typealias Handler = (Int) -> String
  • typealias does not create a new type (a synonym only)
  • No where clause is supported
  • Phase 40 GA

Internal Types (prelude) ​

Pre-declared (no import needed):

TypeMeaning
Optional<T> / T?Optional
Result<T, E>Error return
Range<T>Range
Array<T>Array
Set<T>Set
Dictionary<K, V>Dictionary
ObjectDynamic object
String / Bool / Int / DoubleBasic types
Int8 … Int64 / UInt8 … UInt64Fixed width
Int128 / UInt128128-bit (Phase 38)
Float32 / Float64Floating point
SIMD2/4/8/16<T>SIMD
BigIntArbitrary precision (Phase 46)
CharacterSingle scalar
VoidNo value
Any / AnyObjectAny type

Diagnostics: S004, S008, S010, S011, S017

Usage examples → Language Guide: The Basics · Collections · Enumerations · Opaque Types · SIMD

See also → Expressions · Generic Parameters · Protocols

SYX · Apache-2.0