sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

Proposal: QualifiedMethods #991

Open iskiselev opened 8 years ago

iskiselev commented 8 years ago

Based on my work on #988 and thoughts on #185, #623 I'd like to propose next: Let's introduce QualifiedMethod. Qaulified method will

Such organisation will allow us later solve #185, #623, #990 and provide statically-typed way to call any method with specified signature from TypeScript code.

kg commented 8 years ago

This sounds fine design-wise, but I'd be concerned about the performance implications. Any thoughts on how we can minimize how many layers of function calls it adds and cut down on any indirection?

iskiselev commented 8 years ago

Such method in initial implementation may add only one additional layer to normall call through signature (and will not add anything if compare with call through InterfaceMethod). Direct call of such objects will be nearlt same as current method call without signature.

Really, it may even give us some benefits - if we change our method signature caching algorithms to always use them with in-function caching, our function invocation cache will be always (except variance interface calls) switch with one case and created after first method call.

iskiselev commented 8 years ago

I'll do some benchmarks to understand better if it affects call perfomance.

iskiselev commented 8 years ago

I've implemented extended InterfaceMethod to work with all non-static functions (static will add later). Each type now holds InterfaceMethods for each instance method. Using them to call methods add no overhead comparing to calling method through signature - and even have some benefits, as each InterfaceMethod correspond with only one method overload. So, we don't need use inline cache anymore for all except variance calls. With it I was able to solve #185, #623 (so InheritedAndNewMethod and VirtualAndNewMethods tests are not broken anymore). But it come with price: we should use signature call a little bit oftener and class initialization takes longer time (have not measured how much).