[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [objc-improvements] Warnings when compiling GNUStep

From: Nicola Pero
Subject: Re: [objc-improvements] Warnings when compiling GNUStep
Date: Thu, 4 Sep 2003 10:07:07 +0100 (BST)

> > but since Objective-C allows multiple root classes, the compiler 
> > cannot statically decide to focus on NSObject.
> > What should we do?  I see 3 choices:
> >    (1) Leave things as they are.  Users will be able to suppress the
> > above warning by
> >        casting the receiver to the root class (in above case, '(NSObject
> > *)').
> >    (2) Build a list of all plausible root classes (i.e., classes without
> > superclasses),
> >        and consult all instance methods for those classes when
> > dispatching messages to
> >        'Class'
> >    (3) Treat messages to 'Class' the same way we treat messages to 'id',
> > i.e., consult
> >        all class and instance methods available.  This is what the
> > compiler appears to
> >        have done until now (in its mercurial and buggy way).
> I've implemented 2. in my patch, and I think this is correct and
> consistent with the intention of the current behavior.

I agree.  That is what should happen.  When looking up methods of a
receiver of type 'Class', an instance method of a non-root class should
not be found (big warning!); an instance method of a root class should be
found (no warning if only one is found, warning if conflicting methods are
found).  I think this is correct because this is how messaging works.

There is a slight chance, if you want, that the wrong prototype from the
wrong root class is picked up.  This is perfectly equivalent to the slight
chance that when you send a message to 'id', the wrong prototype from the
wrong class is picked up.

I think the compiler should take a practical but globally consistent
approach and assume (similarly to what it should do for 'id' receivers)  
that, unless the contrary is proven, that the program conforms to the
convention of having all relevant method prototypes declared before the
respective method invocations.  Which means, the compiler can assume it
has seen the root class that the Class object will refer to, so if a
single root class instance method matching the required method is found,
the compiler can assume it's the right one (in the same way that if a
message to an 'id' is sent, and a single method declaration matching it
has been read, the compiler assumes it's the right one).  If multiple ones
are found, of course we're getting into a corner case where something
seems to be not quite right, and a warning should (at least) be generated,
plus some sort of fallback/recovery plan should be used.

I don't see why this check should particularly affect performance.  You
can put all the root instance methods in a table (like the instance and
class methods are now if I remember correctly) and lookup should be pretty
quick - not slower than instance/class method lookup.  Reading Alex's
post, it seems that's what he thinks/did too.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]