This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Turn check macros into functions. (issue6188088)


On 5/16/12, Richard Guenther <richard.guenther@gmail.com> wrote:
> On May 16, 2012 Diego Novillo <dnovillo@google.com> wrote:
> > On 12-05-16 09:00 , Richard Guenther wrote:
> > > On May 16, 2012 Diego Novillo<dnovillo@google.com> wrote:
> > > > On 12-05-16 05:41 , Richard Guenther wrote:
> > > > > What's the reason for templating these functions?
> > > > > They all take trees as parameter!?

The check templates replicate the behavior of the check macros,
which carefully return the type of their argument.  In essence,
the check macros were templates.

> > > > True.  I don't recall what Lawrence had in mind, but I
> > > > remember that by using templates here, you don't need to
> > > > deal with the mess of distinguishing tree from const_tree,
> > > > and having to force constness out with ugly casts.
> > >
> > > Well, but you get no typesafety for it in return.  You can
> > > simply provide a const_tree overload.
> >
> > There's less typing if you use the template variant.  Not sure
> > why you say there is less type safety with templates.
>
> Because it accepts any type as tree argument?  It's of course not
> less type safety than using macros, but less type safety compared
> to not using templates.

The overload works if the only types are tree and const_tree.
In the future, we may wish to refine the types so that, for example,
we can have a pointer to a decl and ask if it is a var decl.

The implementation approach is to make small steps.  It's a tradeoff
between small steps that may show only incremental value, or big
steps that risk rejection.  In addition, merging is easier with
small steps.

> > > With using templates you are also forced to retain these
> > > functions in the header file - another thing that I suppose
> > > you guys were about to "fix"?  It's after all debugging code.
> >
> > No, templated functions must always stay in the header file.
> > There is no changing that.
>
> If they ain't templates they are not templates.  And thus do not
> need to stay in the header.  Not sure what you are after here ;)

Personally, I would like to get to the point where we take advantage
of static typing and the vast bulk of these checks are eliminated.

> > > > Additionally, templates are producing slightly smaller
> > > > code than the non-template variant (about 0.2% smaller).
> > > > I'm not actually sure why this happens, but it's consistent
> > > > across all binaries.
> > >
> > > Well, what did you compare?  Make sure to not have
> > > -fkeep-inline-functions, otherwise you get all bodies as
> > > compared to only the instantiated bodies.
> >
> > Two bootstrapped compilers built exactly the same, except one
> > was using the template version, the other using the straight
> > inline functions with const_tree parameters and CONST_CAST_TREE
> > in return values.
>
> That's of course not exactly the same.  The checking fns should
> be able to unconditionally use const_tree anyway.

The two versions are inline templates functions versus macros.
I expect the non-template version would be roughly the same size
as the template version.

-- 
Lawrence Crowl


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]