[Cuis-dev] Handy ReferenceFinder extension and a question...

Juan Vuletich juan at jvuletich.org
Tue Mar 10 05:45:12 PDT 2020


Hi Phil,

On 3/10/2020 12:06 AM, Phil B via Cuis-dev wrote:
> ...
>
> As far as why we're seeing CompiledMethod at all, I only spot checked 
> the results.  In some cases it wasn't clear why, given the method 
> source code which had backticked `0 at 0` code.  However, in others it 
> seemed reasonable.  For example, something like the following makes sense:
> rect:=`0 at 0 corner: 20 at 20`. "i.e. this is a literal but won't return 
> the literal 0 at 0 instance"
> rect origin == `0 at 0`. "no"
>
> So the logical followup question is why some of the methods don't seem 
> to match the source code?  Just a guess: maybe when they were last 
> recompiled something was broken with the literal syntax? (I'm pretty 
> sure my code is good because everything I checked failed a #== test 
> which is what I wanted)  Since there seemed to be plenty of cases 
> where method recompilation wouldn't address the issue, I just said 
> 'meh, whatever... let's do it this way instead'

You say 'the literal 0 at 0 instance'.

This is the root of your confusion. Suppose you have two different 
methods. They can be in the same class or not.

methodA
   bool := true.
   smallInt := 7.
   largeInt := 
100000000000000000000000000000000000000000000000000000000000000000000000000000000000.
   char := $a.
   symbol := #loveSmalltalk.
   string := 'Yes, I really do.'.

methodB
   bool := true.
   smallInt := 7.
   largeInt := 
100000000000000000000000000000000000000000000000000000000000000000000000000000000000.
   char := $a.
   symbol := #loveSmalltalk.
   string := 'Yes, I really do.'.

Each of these methods will include 5 literals.

- bool will be the same instance in both. If the methods answered bool, 
then 'x methodA == y methodB' would be true.
- smallInt will be the same instance in both. If the methods answered 
smallInt , then 'x methodA == y methodB' would be true.
This is because Booleans and SmallIntegers are immediate, regardless of 
being a method literal or not.

- char will be the same instance in both. If the methods answered char, 
then 'x methodA == y methodB' would be true.
- symbol will be the same instance in both. If the methods answered 
symbol, then 'x methodA == y methodB' would be true.
This is because characters and symbols are unique. Two equal Symbols are 
guaranteed to be the same symbol.

- largeInt will NOT be the same instance in both. If the methods 
answered largeInt, then 'x methodA == y methodB' would answer false.
- Same with string. They will be two different instances.
This is because when the compiler compiles the method, it creates the 
necessary instances of LargePositiveInteger and String, without any 
concern of an equal instance already in existence..

As you see being immediate, unique or a literal are three different things.

The backtick syntax `0 at 0` creates a literal at compile time. But there 
is no guarantee of uniqueness. It just mimics what the compiler does 
when it finds 'a := 1000000000000000000000000', for instance.

So yes, your tool will find all `0 at 0` literals. And they are ok.

Cheers,

-- 
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
@JuanVuletich



More information about the Cuis-dev mailing list