

Can V8 annotate source with Closure Types as it runs? - chrisdew
http://www.barricane.com/2011/10/06/google-v8-to-annotate-source-with-closure-jsdoc-type-expressions.html

======
tlrobinson
(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
Thanks, I hadn't heard of Narcissus - this may do the job.

------
forgotusername
Puzzled 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
Yes, 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.

