Why is there is a need for a run-time type representation?
In general, RTTs allow the programmer to lie about the types in their code.
This is not for programmers but for compilers, as an escape hatch from the static type system (since we can never define a type system that is powerful enough for all languages). The compiler cannot lie to the engine without failing the cast.
@rossberg could you please provide some examples how do you think it could/should be used by compilers?
@bashor, yeah, I should update the Overview to match the MVP. The Overview has basic examples already requiring Wasm-level casts to work around the limitations of the Wasm-level type system (see e.g. the objects or polymorphism examples). But these examples are a bit outdated and do not yet make runtime types explicit.
The short answer is that they are only needed to safely enable such casts, for nothing else. In other VMs (such as the JVM) they are implicit in all objects, but in a low-level machine like Wasm it is desirable to avoid such hidden costs and provide explicit control over all operationally relevant data.
Most helpful comment
This is not for programmers but for compilers, as an escape hatch from the static type system (since we can never define a type system that is powerful enough for all languages). The compiler cannot lie to the engine without failing the cast.