Hi Chris,<br>
<br>
my understanding of a "transparent proxy" is that it automatically forwards all requests, thus requiring special metaprogramming logic to reveal an object as a proxy. On the other hand, "intransparent proxies" would define an explicit list of requests to forward. Not sure however whether this is a useful classification ...<br>
<br>
> > - ProtoObject is still not yet an empty class. For instance, stuff such as #doOnlyOnce: or #scaledIdentityHash should be implemented on Object only. We should continue work on this in the Trunk. You can mitigate this by redefining these messages in your proxy and forwarding them yourself.<br>
> <br>
> It would arguably be a more elegant way of organizing code, but not much else.<br>
<br>
One central difference it that only an empty ProtoObject allows you for defining a truly transparent proxy. Otherwise, you are required to override a larger number of messages and forward each of them yourself.<br>
<br>
> > - Primitive methods do not resolve proxies automatically, i.e., #(1 2 3) at: (MyProxy1 for: 2) would have the primitive failed. My mitigation for this problem was to define an exclusion list for certain classes that should never be wrapped into a proxy, but this is not an ideal solution,<br>
> <br>
> My mitigation strategy was a simple "yourself" on the end.  It instantly gives away to future developers familiar with writing proxy-aware code.  It seems like you're willing to go through to avoid that.<br>
<br>
Well, this might depend on the use case of your proxies. I have a proxy class that automatically wraps every answer into another proxy to decorate an entire object graph, so an exclusion list for certain types felt like the right approach to me. Building a framework, I have also no control about to which primitives the client sends these answered instances.<br>
<br>
> Now you're talkin'!  :-)  Proxy-aware code!!<br>
<br>
I really think this would a small pattern which should be no huge effort to apply to all <primitive:> sends in the Trunk. :-) How could we best design such a pattern? For instance, looking at Object >> #at:<br>
<br>
    <b>at:</b><font color="#000000"> </font><font color="#000080">index</font><font color="#000000"> <br>
</font>    <font color="#000000">    </font><font color="#000000"><</font><font color="#008000"><b>primitive:</b></font><font color="#000000"> </font><font color="#800000">60</font><font color="#000000">></font><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#000080">index</font><font color="#000000"> </font><font color="#000080">isInteger</font><font color="#000000"> </font><font color="#000080">ifTrue:</font><font color="#000000"><br>
</font>    <font color="#000000">        </font><font color="#000000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">class</font><font color="#000000"> </font><font color="#000080">isVariable</font><font color="#000000"><br>
</font>    <font color="#000000">            </font><font color="#000080">ifTrue:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">errorSubscriptBounds:</font><font color="#000000"> </font><font color="#000080">index</font><font color="#008000">]</font><font color="#000000"><br>
</font>    <font color="#000000">            </font><font color="#000080">ifFalse:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">errorNotIndexable</font><font color="#008000">]</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#000080">index</font><font color="#000000"> </font><font color="#000080">isNumber</font><font color="#000000"><br>
</font>    <font color="#000000">        </font><font color="#000080">ifTrue:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">^</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">at:</font><font color="#000000"> </font><font color="#000080">index</font><font color="#000000"> </font><font color="#000080">asInteger</font><font color="#000000">]</font><font color="#000000"><br>
</font>    <font color="#000000">        </font><font color="#000080">ifFalse:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">errorNonIntegerIndex</font><font color="#000000">]</font><br>
<br>
We could insert this statement at the beginning of the method:<br>
<br>
    <font color="#000000">(</font><font color="#000080">index</font><font color="#000000"> </font><font color="#000080">isInteger</font><font color="#000000"> </font><font color="#000080">and:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#800080">(</font><font color="#800000">(</font><font color="#800000">thisContext</font><font color="#000000"> </font><font color="#000080">objectClass:</font><font color="#000000"> </font><font color="#000080">index</font><font color="#800000">)</font><font color="#000000"> </font><font color="#000080">includesBehavior:</font><font color="#000000"> </font><font color="#000000">Integer</font><font color="#800080">)</font><font color="#000000"> </font><font color="#000080">not</font><font color="#008000">]</font><font color="#000000">)</font><font color="#000000"> </font><font color="#000080">ifTrue:</font><font color="#000000"><br>
        </font><font color="#000000">[</font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">at:</font><font color="#000000"> </font><font color="#000080">index</font><font color="#000000"> </font><font color="#000080">yourself</font><font color="#000000">]</font><font color="#000000">.</font><br>
<br>
Object>>#perform:withArguments:inSuperclass: could be rewritten like this:<br>
<br>
    <b>perform:</b><font color="#000000"> </font><font color="#000080">selector</font><font color="#000000"> </font><b>withArguments:</b><font color="#000000"> </font><font color="#000080">argArray</font><font color="#000000"> </font><b>inSuperclass:</b><font color="#000000"> </font><font color="#000080">lookupClass</font><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#000000"><</font><font color="#008000"><b>primitive:</b></font><font color="#000000"> </font><font color="#800000">100</font><font color="#000000">><br>
    +    (</font><font color="#000080">selector</font><font color="#000000"> </font><font color="#000080">isSymbol</font><font color="#000000"> </font><font color="#000080">and:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#800080">(</font><font color="#800000">(</font><font color="#800000">thisContext</font><font color="#000000"> </font><font color="#000080">objectClass:</font><font color="#000000"> </font><font color="#000080">selector</font><font color="#800000">)</font><font color="#000000"> </font><font color="#000080">includesBehavior:</font><font color="#000000"> </font><font color="#000000">Symbol</font><font color="#800080">)</font><font color="#000000"> </font><font color="#000080">not</font><font color="#008000">]</font><font color="#000000">)</font><font color="#000000"><br>
            </font><font color="#000080">ifTrue:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">perform:</font><font color="#000000"> </font><font color="#000080">selector</font><font color="#000000"> </font><font color="#000080">yourself</font><font color="#000000"> </font><font color="#000080">withArguments:</font><font color="#000000"> </font><font color="#000080">argArray</font><font color="#000000"> </font><font color="#000080">inSuperclass:</font><font color="#000000"> </font><font color="#000080">lookupClass</font><font color="#000000">]</font><font color="#000000">.<br>
</font>    <font color="#000000">    </font><font color="#000000">(</font><font color="#000080">selector</font><font color="#000000"> </font><font color="#000080">isSymbol</font><font color="#000000">)</font><font color="#000000"><br>
</font>    <font color="#000000">        </font><font color="#000080">ifFalse:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">error:</font><font color="#000000"> </font><font color="#800080">'selector argument must be a Symbol'</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#000000">(</font><font color="#000080">selector</font><font color="#000000"> </font><font color="#000080">numArgs</font><font color="#000000"> </font><font color="#000080">=</font><font color="#000000"> </font><font color="#000080">argArray</font><font color="#000000"> </font><font color="#000080">size</font><font color="#000000">)</font><font color="#000000"><br>
</font>    <font color="#000000">        </font><font color="#000080">ifFalse:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">error:</font><font color="#000000"> </font><font color="#800080">'incorrect number of arguments'</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#000000">(</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">class</font><font color="#000000"> </font><font color="#000080">==</font><font color="#000000"> </font><font color="#000080">lookupClass</font><font color="#000000"> </font><font color="#000080">or:</font><font color="#000000"> </font><font color="#008000">[</font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">class</font><font color="#000000"> </font><font color="#000080">inheritsFrom:</font><font color="#000000"> </font><font color="#000080">lookupClass</font><font color="#008000">]</font><font color="#000000">)</font><font color="#000000"><br>
</font>    <font color="#000000">        </font><font color="#000080">ifFalse:</font><font color="#000000"> </font><font color="#000000">[</font><font color="#800000">^</font><font color="#000000"> </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">error:</font><font color="#000000"> </font><font color="#800080">'lookupClass is not in my inheritance chain'</font><font color="#000000">]</font><font color="#000000">.</font><font color="#000000"><br>
</font>    <font color="#000000">    </font><font color="#800000">self</font><font color="#000000"> </font><font color="#000080">primitiveFailed</font><br>
<br>
And so on for almost all the other primitive users as well.<br>
For #==, it would be harder because our current semantics of identity say that a proxy has its own identity, and it would probably be a bad decision to change this semantics. Maybe we would need a differentiation between "proxy-aware identity" and "effective identity", and #= (like in Symbol >> #=) would be one of many cases where the latter concept would be required. But complexity is increasing right now ...<br>
<br>
See also the discussion about the right place for the mirror protocol. [1]<br>
Any other ideas how we could minify/beautify the above pattern? :-)<br>
<br>
Best,<br>
Christoph<br>
<br>
[1] <a href="http://lists.squeakfoundation.org/pipermail/squeak-dev/2022-January/218221.html">http://lists.squeakfoundation.org/pipermail/squeak-dev/2022-January/218221.html</a><br>
<br>
<font color="#808080">---<br>
</font><font color="#808080"><i>Sent from </i></font><font color="#808080"><i><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><u><font color="#808080">Squeak Inbox Talk</font></u></a></i></font><br>
<br>
On 2022-01-15T18:51:00-06:00, asqueaker@gmail.com wrote:<br>
<br>
> Hi Craig,<br>
> <br>
> >       Indeed, none of our code should be proxy-aware.<br>
> <br>
> I certainly would agree with the statement, "it would be nice if none<br>
> of our code needed to be proxy-aware," but I don't yet understand how<br>
> it's possible, regardless where the implementation details are handled<br>
> (VM or image).  As a VM expert, I can appreciate you preferring to use<br>
> VM-based proxies.  The only downside is that those who only understand<br>
> Smalltalk and not the secret innards of the VM cannot realistically<br>
> participate in Squeak anymore if they wish or need to use the classic<br>
> Proxy pattern.  We broke the code and also legacy systems for that.<br>
> <br>
> Which is why I keep bringing up just this one example on Symbol<br>
> and hoping someone can explain it to help me get unstuck.  Would you<br>
> follow its code with me, line by line, below?  Let's pretend the<br>
> receiver is the symbol #size, and the argument, aSymbol, comes in as<br>
> an instance of MyProxy, which refers to an Integer oid that ultimately<br>
> will reify to the receiver object (#size)).<br>
> <br>
> It's easy to see why the code no longer works for the traditional Proxy pattern:<br>
> <br>
>    = aSymbol       "<------ aSymbol comes in as a MyProxy instance"<br>
>         self == aSymbol ifTrue: [^ true].       "<---- false, continue"<br>
>         aSymbol isSymbol ifTrue: [^ false].  "<----- true, return false.  BUG!"<br>
>         "Use String comparison otherwise"<br>
>         ^ super = aSymbol<br>
> <br>
> So what about when aVMProxy instance is passed in?  I'm so used to<br>
> normal Smalltalk-think, I'm not even able to think about WHEN or HOW<br>
> the VM would perform it's magic handling of the incoming VMProxy<br>
> instance to make this work.  I guess this is a trade-off -- we don't<br>
> have to think about Proxy's, but we have to know about and think about<br>
> VM magic.  I'm willing to try, but I don't even know where to begin.<br>
> Would you help?<br>
> <br>
> Regards,<br>
>   Chris