-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime Type Testing via Tags #13
Comments
Another interesting option is to have a file-level tag system (this is perhaps similar in some ways to the idea of "selector colouring" [1]). Roughly speaking, every file would have an array (
To reduce the cost when transferring data between files, we can implement some standard tags for primitives (as above). But, even so, there is two major issues:
An interesting thing that could be done would be to perform some kind of type tag optimisation when compiling multiple files together. References
|
At this point, its still pretty unclear to me what the best option is. I think there are at least two things to consider:
Arrgggh. |
The current approach to runtime type testing is based on runtime interrogation. That is, by exploiting the available type information provided by JavaScript, it checks on demand whether a given value is an instance of a given type. This approach has been pretty successful and is relatively easy to implement. The current could be further optimised. Regardless, there are a few challenges for this approach which are difficult or impossible to overcome:
These two issues raise the obvious and immediate question as to whether an alternative approach is possible. In particular, an approach based on type tags has been long touted as the ideal solution. But, can it work?
Here is a current list of known challenges for a tag based approach:
any
type does pose a fairly significant problem for a tag based approach. The key problem is that there is no obvious way to generate an appropriate tag. The only real solution is to embed the full type of the value in question as the tag. This is workable (I believe) and would essentially cause some minor performance problems only in the case of theany
type. The other obvious option is to remove theany
type altogether.int|null
flows into a variable of typeint|null|bool
. The key to minimising the need for this would be to somehow divide up the space (e.g.int
is always tag value 0, etc).A possible space for tags might be:
null
== 0bool
== 1byte
== 2int
== 3[]
== 4&
== 5{
== 6Remember that we don't have to encode tags for union, intersection or negation types. This is because values are concrete and cannot have that type. Furthermore, nested union types will correspond to nested tags.
NOTE: Probably, it would help a lot if support for tagging was built into WyIL bytecode. For example, if the necessary tag conversion and introduction points were already identified.
The text was updated successfully, but these errors were encountered: