-
-
Notifications
You must be signed in to change notification settings - Fork 683
Description
Question
When implementing a non-JS host that needs to create and read managed AssemblyScript objects (strings, complex maps, nested arrays) it does so directly via WASM exports (__new, __pin, __unpin) and linear memory access.
This works well for strings (rtId == 2) but problem arises with more complex types, such as Array<T> where T is a managed type.
Class IDs are assigned sequentially at compile time, which means the ID for Array depends on which other types appear in the module before it.
The JS loader works around this because users pass the ID explicitly from the JS side, having obtained it from idof<Array>() in the AS source or from the generated static bindings, which embed IDs as compile-time constants.
Is there a better way to discover class IDs at runtime without requiring the module author to export them explicitly?
I looked into the RTTI table and it seems that it only contains flags for each class, but not the full type information.
For example, all of these types Array<string>/ Array<Array<i32>>/ Array<Array<string>>/ Array<Array<Array<f32>>> produce identical flags ARRAY | VAL_ALIGN=4B | VAL_MANAGED.
Is there way for a host to fully reconstruct the type tree from the RTTI table alone, without needing idof exports?