public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jeff Law <law@redhat.com>
To: David Malcolm <dmalcolm@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH 2/4 v2] libcpp: Replace macro usage with C++ constructs)
Date: Fri, 08 May 2015 21:45:00 -0000	[thread overview]
Message-ID: <554D2E65.4010802@redhat.com> (raw)
In-Reply-To: <1430850074-40522-1-git-send-email-dmalcolm@redhat.com>

On 05/05/2015 12:21 PM, David Malcolm wrote:
> On Mon, 2015-05-04 at 13:15 -0600, Jeff Law wrote:
> On 05/01/2015 06:56 PM, David Malcolm wrote:
>>>
>>> [I didn't mark the inline functions as "static"; should they be?]
Just a follow-up on this.  I got burned by the ODR issues around 
implicit extern inlines earlier this week.  Basically I had two distinct 
implementations for an inline function with the same name.  They 
obviously appeared in different "header files".

When optimizng, this was fine as they'd actually get inlined and all was 
good.  Things blew up when the optimizer was off.  We got two functions 
with the same name, but different implementations.  The linker blindly 
chose one for me, and in one context it was the wrong one.

This led to bootstrap comparison failures.

So, just be careful :-)

>>
> I moved linemap_assert and linemap_assert_fails higher up within the
> file so that they can appear before the bodies of the inline functions.
> I didn't change their implementation; it's a simple cut-and-paste, so
> these hunks are just an artifact of git's diff-ing algorithm getting
> confused by that.
>
> Should I have called that out in the ChangeLog entries?
It might have helped.  Or you could have pulled it out like you did in 
the follow-up.  No worries.  So consider the issues raised in that code 
as a non-issues for your patch.  They'd be nice things to clean up 
someday though.

>> -#define LINEMAPS_MAPS(SET, MAP_KIND) \
>>> -  (LINEMAPS_MAP_INFO (SET, MAP_KIND))->maps
>>> +inline line_map *
>>> +LINEMAPS_MAPS (const line_maps *set, bool map_kind)
>>> +{
>>> +  return LINEMAPS_MAP_INFO (set, map_kind)->maps;
>>> +}
>>> +
>>> +inline line_map * &
>>> +LINEMAPS_MAPS (line_maps *set, bool map_kind)
>>> +{
>>> +  return LINEMAPS_MAP_INFO (set, map_kind)->maps;
>>> +}
>> Do we really need two implementation of those various functions, one for
>> const line_maps * the other for line_maps *?
>>
>
> The issue here is when they are accessed as lvalues, rather than just as
> rvalues.
>
> I've had a go at eliminating some of the lvalue ones as a followup
> patch: given that after patch 4 these become just field accesses, it's
> trivial to turn the usage sites into plain accesses of fields.
>
> Is that desirable, or are the uses of the macros regarded as useful
> (e.g. for grepping)?  (my preference is for the former: to turn them
> into plain field accesses at those sites)
I think macros would only be useful for those already familiar with the 
code.  If I'm looking for how a particular field gets accessed, I'm 
generally going to be grepping for the field.

Of course, if the field have names that are common ("next" anyone?), 
then, well, grepping for field names is pointless.


>
> Ironically, one of the ones that isn't so easy to eliminate is the
> one you called out above.  Eliminating those ones made the code messier,
> so I kept those ones.
lol.  I just picked one after seeing the pattern repeat a bit.
>
> I'm sending updated patches; the old patch 2 split into 2 parts, and
> a followup ("patch 5 of 4", as it were):
>
>    [PATCH 2/4 v2: part 1] Move linemap_assert higher up within the file
>    [PATCH 2/4 v2: part 2] libcpp: Replace macro usage with C++ constructs
>    [PATCH 5/4] libcpp: Eliminate most of the non-const/reference-returning inline fns
>
> Do I need to do any performance testing of this kit?  Given that the
> resulting inline functions become trivial field lookups in patch 4,
> I'm assuming that our inliner is good enough to optimize it as well
> as the status quo implementation.
Yea, I wouldn't worry about performance of an inline field access vs a 
macro.  We should be good to go.

>
> Also, for comments before functions, do we prefer a blank line between
> the comment and decl, or for them to abutt?
>
> /* Foo.  */
>
> foo ();
>
> vs
>
> /* Bar.  */
> bar ();
>
> How do the following look?
I've done both in my days. I try to follow whatever is in the nearby code.

Let me have a look at the followup...

jeff

  parent reply	other threads:[~2015-05-08 21:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-02  0:44 [PATCH 0/4] libcpp patches David Malcolm
2015-05-02  0:44 ` [PATCH 4/4] Replace line_map union with C++ class hierarchy David Malcolm
2015-05-04 20:45   ` Jeff Law
2015-05-04 21:34     ` David Malcolm
2015-05-14 15:20       ` Jeff Law
2015-05-02  0:44 ` [PATCH 3/4] libcpp/input.c: Add a way to visualize the linemaps David Malcolm
2015-05-04 19:20   ` Jeff Law
2015-05-13 14:05     ` David Malcolm
2015-05-02  0:44 ` [PATCH 1/4] libcpp: Improvements to comments in line-map.h/c David Malcolm
2015-05-04 17:18   ` Jeff Law
2015-05-02  0:44 ` [PATCH 2/4] libcpp: Replace macro usage with C++ constructs David Malcolm
2015-05-04 19:15   ` Jeff Law
2015-05-05 18:08     ` [PATCH 2/4 v2] libcpp: Replace macro usage with C++ constructs) David Malcolm
2015-05-05 18:08       ` [PATCH 5/4] libcpp: Eliminate most of the non-const/reference-returning inline fns David Malcolm
2015-05-08 21:49         ` Jeff Law
2015-05-05 18:08       ` [PATCH 2/4 v2: part 1] Move linemap_assert higher up within the file David Malcolm
2015-05-08 21:35         ` Jeff Law
2015-05-05 18:08       ` [PATCH 2/4 v2: part 2] libcpp: Replace macro usage with C++ constructs David Malcolm
2015-05-08 21:47         ` Jeff Law
2015-07-08 14:50         ` Thomas Schwinge
2015-07-08 15:14           ` David Malcolm
2015-05-08 21:45       ` Jeff Law [this message]
2015-05-10 15:39         ` [PATCH 2/4 v2] libcpp: Replace macro usage with C++ constructs) Jan Hubicka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=554D2E65.4010802@redhat.com \
    --to=law@redhat.com \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).