compiler whitewash

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

compiler whitewash

Eliot Miranda-2
hi compiler hackers....

in Squeak trunk evaluate the following, proceeding through the warning that t appears to be uninitialized when send ifNil:

| t |
t ifNil: [#ignore].
3 + 4


7 is printed between the "t" and the "ifNil:".  It would be nice if it were still printed after the 3 + 4.  wanna fix it?
--
best,
Eliot


Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

Balázs Kósi-2
hi,

I have a quick fix, tested only with your example.
It just stores the original selection and restores it after the query.
Change Parser >> #queryUndefined to:

Parser >> queryUndefined
    | varStart varName originalStart originalStop |
    originalStart := cue requestor startIndex.
    originalStop := cue requestor stopIndex.
    varName := parseNode key.
    varStart := self endOfLastToken + requestorOffset - varName size + 1.
    cue requestor selectFrom: varStart to: varStart + varName size - 1; select.
    (UndefinedVariable name: varName) ifFalse: [^ self fail].
    cue requestor selectFrom: originalStart to: originalStop; select.

Cheers, Balazs

On Wed, Oct 22, 2014 at 2:12 AM, Eliot Miranda <[hidden email]> wrote:
hi compiler hackers....

in Squeak trunk evaluate the following, proceeding through the warning that t appears to be uninitialized when send ifNil:

| t |
t ifNil: [#ignore].
3 + 4


7 is printed between the "t" and the "ifNil:".  It would be nice if it were still printed after the 3 + 4.  wanna fix it?
--
best,
Eliot






Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

marcel.taeumel (old)
In reply to this post by Eliot Miranda-2
Would be nice if there is no warning at all if you write this kind of code. :)

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

Eliot Miranda-2


On Thu, Oct 23, 2014 at 9:20 AM, Marcel Taeumel <[hidden email]> wrote:
Would be nice if there is no warning at all if you write this kind of code.
:)

you mean you don't want to be warned of use of uninitialized variables or something else?  If the former I disagree  I find the warning very useful, and hence put up with the annoyance when I'm depending on the variable having been initialized to nil.
 

Best,
Marcel



--
View this message in context: http://forum.world.st/compiler-whitewash-tp4785831p4786244.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.




--
best,
Eliot


Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

marcel.taeumel (old)
In this code example, the programmer was aware if the nil-case, which is the same as uninitialized. I find it sometimes strange to have to write "x := nil." in an algorithm just to get rid of this message.

In other cases, this warning is fine. :) Maybe there are some patterns that indicate that "not initialized" is totally fine. Maybe it is just the case when #ifNil: is explicitely found in the code.

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

marcel.taeumel (old)
Some addon: I personally think that all variables are initialized with "nil". :)

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

Eliot Miranda-2


On Thu, Oct 23, 2014 at 11:03 AM, Marcel Taeumel <[hidden email]> wrote:
Some addon: I personally think that all variables are initialized with "nil".
:)

Yes they are, and its one of the nice guarantees that Smalltalk makes that all variables are initialized either to nil or, in non-object data to 0 or Character value: 0.  But the compiler can't in general tell whether a reference to a variable before it is assigned to is a mistake or not.  For example in this:

| t |
self doSomethingWith: t

the compiler can't know whether t is being used correctly or not ever.  It is pointless for the compiler to try and analyse any relevant implementations of doSomethingWith: looking for e.g. ifNil: guards since doSomethingWith: can be redefined.  Marcel, do you have some concrete criteria for squashing the warning in certain cases?  If you have a good set of criteria we can implement them, otherwise I think we have to accept the inaccuracy of the warning.


Best,
Marcel



--
View this message in context: http://forum.world.st/compiler-whitewash-tp4785831p4786264.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.




--
best,
Eliot


Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

marcel.taeumel (old)
Hmm... I agree that you cannot easily analyse statically some called method and make sense out of it considering the initialization of its arguments/receiver. But what about:

| x |
...
[x notNil] whileTrue: [
   ...
   ... ifTrue: [x := #foobar]].
...

In this case, the initialization is kind of deferred in the very same method. Maybe I wrote bad Smalltalk code, but I had this several times. Finding some object in a complex structure or so... So this could be detected, right? :)

[It is not that I am really that annoyed by these compiler warnings because I made them non-modal in my tools.]

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: compiler whitewash

marcel.taeumel (old)
I meant:

| x |
...
[x isNil] whileTrue: [
   ...
   ... ifTrue: [x := #foobar]].
...