unknown represents any single-slot TVM value with contents unknown at compile-time.
Primary use
tuple is an alias for array<unknown>:
tuple has all the array methods: push, size, and others. Such arrays are opaque, so the push method accepts values of any type:
Manual type casts with as operator
Any type T can be cast to unknown using the as operator. If T is a primitive that fits in a single stack slot, the cast is a no-op. Otherwise, the object is packed into a sub-tuple:
unknown value, cast it to a known type with as.
Exception arguments
In TVM, an exception can carry some value in an arbitrary stack slot. The syntaxthrow (code, arg) allows attaching an argument arg of unknown type:
Point in throw (code, Point { ... }) will be packed to a single slot of unknown type. Casting arg as Point will unpack that unknown back.
Be extremely careful using unknown
Using unknown incorrectly may lead to runtime errors or stack corruption. Always extract a value of the exact type it was originally stored in.
For example, this usage is invalid:
x has been smart cast to int when it was placed into the array t:
Stack layout and serialization
A value of typeunknown takes a single TVM slot with any valid value at runtime. It cannot be serialized because the exact value type is not known.