3 ms·
Can V8 annotate source with Closure Types as it runs?
- tlrobinson 15y ago(If I understand correctly) I'd write transcompiler (based on Narcissus or whatever) to instrument your code with statements at the top of each function to check and record the types. I think a basic version of this could be built in a day. Advantages of instrumenting the code: 1. No mucking around in V8 internals. 2. Works on any JavaScript engine.
- chrisdew 15y agoThanks, I hadn't heard of Narcissus - this may do the job.
- forgotusername 15y agoPuzzled why you'd want this. So you trace the execution of a dynamic program in an attempt to determine all possible variable types, only to annotate its source with those types, so that on next compilation.. the compiler can statically enforce that the same code that created that trace doesn't violate the types deduced from it? (It seems to me the only possible use for doing this would be to test the tracing implementation is sound!) Or perhaps it's for documentation or something. In that case, it'd be a hell of a lot of hand-editing to remove noise from the output. Another side, the set of types used by any variable may be affected by program inputs, so the result can never be complete, unless you run V8 for every possible program input (likely an impossible task).
- chrisdew 15y agoYes, mostly for documentation, and also to spot any unexpected types. I would like to run this during automated testing. For modules where code coverage is 100%, it could be possible that most input-dependent type paths are covered.
- tlrobinson 15y agoOnce the annotations are added (and presumably verified by the developer), Closure can do more aggressive optimizations like stripping unused code, etc.