[squeak-dev] recompile:[from:]

Eliot Miranda eliot.miranda at gmail.com
Tue Feb 11 19:45:31 UTC 2020


Hi All,

    I find myself using something like this to copy methods across
hierarchies:

[:s| | class |
self halt.
class := CogVMSimulator whichClassIncludesSelector: s.
StackInterpreterSimulator recompile: s from: class.
StackInterpreterSimulator organization classify: s under: (class
whichCategoryIncludesSelector: s)] value: #printStringOf:on:.

because if one simply does recompile:from: and the selector doesn't exist
in the target then one ends up with a hidden selector; it's in the method
dictionary but because it isn't in the organization it doesn't show in the
browser or in Monticello etc.

The rationale for not having recompile:from: check the organization is a
good one; when recompiling a class that has changed shape (had inst vars
added or removed) we don't want to waste cycles checking something
redundant. So how about having ClassDescription>>recompile:from: doing the
check if the receiver doesn't equal the argument class, e.g.:

ClassDescription>>recompile: selector from: oldClass
"Preserve the originalTraitMethod (if any) after recompiling a selector"
| oldMethod |
oldMethod := oldClass compiledMethodAt: selector.
super recompile: selector from: oldClass.
oldMethod originalTraitMethod ifNotNil:
[:traitMethod|
(self compiledMethodAt: selector) originalTraitMethod: traitMethod].
(self ~~ oldClass
and: [(organization numberOfCategoryOfElement: selector) = 0]) ifTrue:
[organization classify: selector under: (oldClass
whichCategoryIncludesSelector: oldClass)]

_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200211/80c0c341/attachment-0001.html>


More information about the Squeak-dev mailing list