From: Thomas Enebo Date: 2009-02-26T07:05:27+09:00 Subject: [ruby-core:22519] Re: YASNP (Yet Another Selector Namespace Proposal) Ola Bini wrote: > Charles Oliver Nutter wrote: >> Ola Bini wrote: >>> I definitely like this thinking. As I see a selector proposal, it >>> basically works like this: >>> every method call has an associated namespace. that namespace >>> defaults to the Parsing Default for that file. >>> if a namespace is set for a file, then THAT namespace will be the >>> Parsing Default for that file. >>> of course, this means that namespaces/selectors should just be names >>> - not modules. >> >> They certainly could be names, or the namespaces could be declared in >> a new way that the parser is more aware of. Using modules right now >> is mostly for convenience. >> >>> When you start having modules as namespaces, then it gets really >>> complicated to see what is actually scoped inside of another >>> namespace or not, since the parser can't know this. >> >> My prototype is basically just overloading modules to use as a method >> bag. In this sense it's similar to the "borrow" feature you added to >> JRuby to steal methods from a target module or class. >> >> As for the resolution of the namespace, I think doing it once when >> the "using" is encountered at runtime would work fine. >> >> - Charlie >> >> > Well, my point was that in that case namespaces/selectors isn't > strictly a parse time feature, and as such will incur a cost on EVERY > method call in the lexical scope of a namespace - since you don't know > which CALL/FCALL/VCALL will actually resolve into something that is > part of the other namespace. Which means you'll have to create > SEL_CALL nodes for all CALL nodes inside of that lexical scope, since > all can potentially be a namespaced call. This will incur a heavy > performance cost which I think was one of the main objectives to avoid > in the original proposal. Heavy? or just an additional cost? All nodes in that file will need to be sel_call or something which is aware it needs namespace resolution...which will be an additional cost, but it will also be able to callsite cache the result like our ordinary calls do. So in that sense most applications will not really see the cost. -Tom