public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dodji Seketeli <dodji@redhat.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gcc-patches@gcc.gnu.org, joseph@codesourcery.com,
	       gdr@integrable-solutions.net, lopezibanez@gmail.com
Subject: Re: [PATCH 1/6] Linemap infrastructure for virtual locations
Date: Tue, 12 Apr 2011 14:39:00 -0000	[thread overview]
Message-ID: <m3oc4bedph.fsf@redhat.com> (raw)
In-Reply-To: <m31v4qt2yg.fsf@fleche.redhat.com> (Tom Tromey's message of "Thu,	06 Jan 2011 09:24:39 -0700")

Hello,

Sorry for getting back to this just now, and thank you very much for the
review.  Please find below my reply to your comments.

Tom Tromey <tromey@redhat.com> writes:

> Dodji>    expanded_location xloc;
> Dodji>    if (loc <= BUILTINS_LOCATION)
> Dodji> -    {
> Dodji> -      xloc.file = loc == UNKNOWN_LOCATION ? NULL : _("<built-in>");
> Dodji> +    {      
> Dodji> +      /* If LOC is UNKNOWN_LOCATION and there was a map allocated for
> Dodji> +	 it then XLOC.FILE should be the file path of the map,
> Dodji> +	 i.e. the file path of the main file being compiled.
> Dodji> +	 Otherwise [if we are being called before any line map has
> Dodji> +	 been allocated, e.g. during parsing of commande line
> Dodji> +	 options] if no line map has been allocated yet, then
> Dodji> +	 XLOC.FILE should just be NULL.  */
> Dodji> +      if (loc == UNKNOWN_LOCATION)
> Dodji> +	{
> Dodji> +	  const struct line_map *map =
> Dodji> +	    linemap_lookup (line_table, UNKNOWN_LOCATION);
> Dodji> +	  xloc.file = map != NULL ? LINEMAP_FILE (map) : NULL;
> Dodji> +	}
> 
> I don't understand this.  I thought that UNKNOWN_LOCATION should never
> have an associated file.  This is handled in a funny way: each front end
> is responsible for ensuring that this holds true (this could be cleaned
> up...).
> 
> Am I mistaken about this?  Or is something weird happening after this
> patch?

I was confused.  I realize now this was some papering over what I later
realized was PR preprocessor/48532, that I filed separately along with a
patch.  I have thus removed this hunk from my local copy of the patch.

> 
> Dodji> @@ -883,14 +884,14 @@ static void
> Dodji>  do_line (cpp_reader *pfile)
> Dodji>  {
> Dodji>    const struct line_maps *line_table = pfile->line_table;
> Dodji> -  const struct line_map *map = &line_table->maps[line_table->used - 1];
> Dodji> +  const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
>  
> Dodji>    /* skip_rest_of_line() may cause line table to be realloc()ed so note down
> Dodji>       sysp right now.  */
>  
> Dodji> -  unsigned char map_sysp = map->sysp;
> Dodji> +  unsigned char map_sysp = map->d.ordinary.sysp;
> Dodji>    const cpp_token *token;
> Dodji> -  const char *new_file = map->to_file;
> Dodji> +  const char *new_file = map->d.ordinary.to_file;
> 
> Did you want to use the accessor macros here?
> If not, why not?

Oops.  Yes of course I wanted to use the accessor macros there.  I have
just done it on my local copy of the patch now.  Thanks.

> 
> Dodji>    /* C99 raised the minimum limit on #line numbers.  */
> Dodji> @@ -945,11 +946,11 @@ static void
> Dodji>  do_linemarker (cpp_reader *pfile)
> Dodji>  {
> Dodji>    const struct line_maps *line_table = pfile->line_table;
> Dodji> -  const struct line_map *map = &line_table->maps[line_table->used - 1];
> Dodji> +  const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
> Dodji>    const cpp_token *token;
> Dodji> -  const char *new_file = map->to_file;
> Dodji> +  const char *new_file = map->d.ordinary.to_file;
> Dodji>    linenum_type new_lineno;
> Dodji> -  unsigned int new_sysp = map->sysp;
> Dodji> +  unsigned int new_sysp = map->d.ordinary.sysp;
> 
> Likewise.
> 
> Dodji>    if (map != NULL)
> Dodji> -    linemap_line_start (pfile->line_table, map->to_line, 127);
> Dodji> +    linemap_line_start (pfile->line_table, map->d.ordinary.to_line, 127);
> 
> Likewise.
> 
> Dodji> +  int sysp = (LINEMAPS_ORDINARY_HIGHEST_LINE (pfile->line_table) > 1)
> Dodji> +    && (pfile->buffer ? pfile->buffer->sysp : 0);
> 
> The indentation is off here.
> Put another paren after the '=' and emacs will DTRT.

Done, thanks.

> 
> Dodji> +   physicall source locations are called "spelling locations".
> 
> Typo, should be "physical".
> 
> Dodji> +/* A set of chronological line_map structures.  */
> Dodji> +struct GTY(()) line_maps {
> Dodji> +  
> Dodji> +  struct maps_info info_ordinary;
> Dodji> +
> Dodji> +  struct maps_info info_macro;
> 
> One thing to note is that there may be some code that assumes an
> ordering of location values.  If you hand out ordinary and macro
> locations separately (which I think is what is going on), then code
> doing this may break.

Argh.  The reason why I am doing this is to avoid the (huge) increase of
memory usage due to the fact that the presence of a macro map was
triggering the creation of one more standard map.  Given the number of
macros in some TU, that was starting to add up.  We have discussed this
off-line and a possible way to avoid that was to separate the "integer
space" of locations mapped into macro maps from the integer space of
locations mapped into ordinary maps.  Of course, locations from a given
integer space (be it the space of macro tokens locations or ordinary
token location) is ordered.  This also eases the map lookup as a simple
comparisons is enough to know if a given location is of a token coming
from a macro expansion or not.

Now I think I am left with two options, I guess.  Either I find a way to
make the two kind of locations (those mapped into macro maps and those
mapped into ordinary maps) share the same integer space and be ordered,
or, I spot the places in the code that assume an ordering of all
location values and I change that.

Is the location ordering a strong property we want to keep?

> 
> My recollection is that maybe the diagnostic code did this?
> Or maybe it was someplace more obscure :-(
> Did you happen to run across this while working on this patch?

I haven't noticed that with my tests.  But after reading this, I have
found one spot of the in diagnostic_report_diagnostic that does this.  I
don't know yet if there are other places.

> 
> Dodji> -      fname = pfile->line_table->maps[pfile->line_table->used-1].to_file;
> Dodji> +      fname = (LINEMAPS_LAST_ORDINARY_MAP (pfile->line_table))->d.ordinary.to_file;
> 
> Accessor?

Oops, fixed in my local copy of the patch.

> 
> Dodji> +/* Add a mapping of logical source line to physical source file and
> Dodji> +   line number. This function creates an "ordinary map", which is a
> Dodji> +   map that records locations of tokens that are not part of macro
> Dodji> +   replacement-lists present at a macro expansion point.
> Dodji> +
> Dodji> +   The text pointed to by TO_FILE must have a lifetime
> Dodji> +   at least as long as the lifetime of SET.  An empty
> Dodji> +   TO_FILE means standard input.  If reason is LC_LEAVE, and
> Dodji> +   TO_FILE is NULL, then TO_FILE, TO_LINE and SYSP are given their
> Dodji> +   natural values considering the file we are returning to.
> Dodji> +
> Dodji> +   A call to this function can relocate the previous set of
> Dodji> +   maps, so any stored line_map pointers should not be used.  */
> Dodji> +
> Dodji> +const struct line_map *
> Dodji> +linemap_add (struct line_maps *set, enum lc_reason reason,
> Dodji> +	     unsigned int sysp, const char *to_file, linenum_type to_line)
> 
> I would generally prefer for explanatory comments for public functions
> to be in the header, not by the implementation.  This is more in keeping
> with the current style of the line map code, but I also like it because
> it provides a single text for users of the library to read.

Ah.  I did this because:

     - I thought it was in line of the rest of the code of libcpp (and
       GCC).  I didn't realize it was done on purpose in line-map.h
       only.
     - Having the documentation be at the place where etags points you
       to when you look for a function seemed very convenient to me.  -
       It seems to me that having the documentation near the definition
       helps in keeping the document and the definition in sync.

But if you want, I can just move the the comments to the header file,
no problem at all.

-- 
		Dodji

  reply	other threads:[~2011-04-12 14:39 UTC|newest]

Thread overview: 139+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-10 11:27 [PATCH 0/6] Tracking locations of tokens resulting from macro expansion Dodji Seketeli
2010-12-10 11:16 ` [PATCH 4/6] Support -fdebug-cpp option Dodji Seketeli
2010-12-10 11:16 ` [PATCH 0/6] *** SUBJECT HERE *** Dodji Seketeli
2010-12-10 12:56   ` Dave Korn
2010-12-10 11:27 ` [PATCH 5/6] Add line map statistics to -fmem-report output Dodji Seketeli
2010-12-21  7:30   ` Gabriel Dos Reis
2011-04-13 20:08     ` Dodji Seketeli
2010-12-10 11:27 ` [PATCH 3/6] Emit macro expansion related diagnostics Dodji Seketeli
2010-12-13 15:25   ` Paolo Bonzini
2010-12-13 15:38     ` Paolo Bonzini
2010-12-13 16:30     ` Manuel López-Ibáñez
2010-12-14  7:24     ` Dodji Seketeli
2010-12-14  7:28       ` Gabriel Dos Reis
2010-12-14  8:40         ` Dodji Seketeli
2010-12-14  9:38           ` Gabriel Dos Reis
2010-12-14  9:42             ` Dodji Seketeli
2010-12-14  9:48               ` Gabriel Dos Reis
2010-12-14  7:28     ` Dodji Seketeli
2010-12-14  8:19       ` Gabriel Dos Reis
2010-12-14  8:31         ` Paolo Bonzini
2010-12-14  9:23           ` Dodji Seketeli
2010-12-10 11:53 ` [PATCH 1/6] Linemap infrastructure for virtual locations Dodji Seketeli
2011-01-06 16:48   ` Tom Tromey
2011-04-12 14:39     ` Dodji Seketeli [this message]
2011-04-14 14:46       ` Tom Tromey
2010-12-10 12:27 ` [PATCH 2/6] Generate virtual locations for tokens Dodji Seketeli
2010-12-10 12:33 ` [PATCH 6/6] Kill pedantic warnings on system headers macros Dodji Seketeli
2010-12-10 12:52 ` [PATCH 0/6] Tracking locations of tokens resulting from macro expansion Gabriel Dos Reis
2010-12-10 18:22   ` Dodji Seketeli
2010-12-10 16:59 ` Jeff Law
2010-12-10 19:00   ` Dodji Seketeli
2010-12-13 15:10     ` Jeff Law
2010-12-13 16:35       ` Gabriel Dos Reis
2010-12-14  9:24         ` Dodji Seketeli
2010-12-14  9:40           ` Gabriel Dos Reis
2010-12-14  9:45             ` Dodji Seketeli
2011-07-16 14:38 ` [PATCH 0/7] " Dodji Seketeli
     [not found]   ` <cover.1310824120.git.dodji@redhat.com>
2011-07-16 14:38     ` [PATCH 6/7] Kill pedantic warnings on system headers macros Dodji Seketeli
2011-09-12 22:09       ` Jason Merrill
2011-09-16 11:25         ` Dodji Seketeli
2011-09-17 22:34           ` Jason Merrill
2011-09-18 18:59             ` Dodji Seketeli
2011-07-16 14:38     ` [PATCH 3/7] Emit macro expansion related diagnostics Dodji Seketeli
2011-08-04 15:32       ` Dodji Seketeli
2011-09-12 21:54         ` Jason Merrill
2011-09-16  8:19           ` Dodji Seketeli
2011-09-17 21:27             ` Jason Merrill
2011-09-19 14:37               ` Dodji Seketeli
2011-09-19 19:47                 ` Jason Merrill
2011-09-19 21:27                   ` Jason Merrill
2011-09-20  8:47                     ` Dodji Seketeli
2011-09-20 14:12                       ` Jason Merrill
2011-09-20 14:12                         ` Dodji Seketeli
2011-09-21  2:51                           ` Jason Merrill
2011-09-21 19:09                             ` Dodji Seketeli
2011-09-22 15:32                               ` Jason Merrill
2011-09-26 21:11                                 ` Dodji Seketeli
2011-09-26 22:30                                   ` Jason Merrill
2011-09-27 18:43                                     ` Dodji Seketeli
2011-09-29  7:05                                       ` Jason Merrill
2011-09-29 19:20                                         ` Dodji Seketeli
2011-09-29 21:25                                           ` Jason Merrill
2011-09-29 23:33                                             ` Dodji Seketeli
2011-09-30 15:56                                               ` Jason Merrill
2011-09-30 21:04                                                 ` Jason Merrill
2011-10-03 22:50                                                   ` Dodji Seketeli
2011-10-04 19:59                                                     ` Jason Merrill
2011-10-04 20:35                                                       ` Dodji Seketeli
2011-10-03 20:09                                                 ` Dodji Seketeli
2011-10-04 20:03                                                   ` Jason Merrill
2011-10-04 20:28                                                     ` Dodji Seketeli
2011-09-20  0:08                   ` Dodji Seketeli
2011-07-16 14:39     ` [PATCH 5/7] Add line map statistics to -fmem-report output Dodji Seketeli
2011-09-12 22:07       ` Jason Merrill
2011-09-16  8:29         ` Dodji Seketeli
2011-09-17 22:05           ` Jason Merrill
2011-09-20 12:10             ` Dodji Seketeli
2011-09-20 14:08               ` Jason Merrill
2011-07-16 14:39     ` [PATCH 4/7] Support -fdebug-cpp option Dodji Seketeli
2011-08-21 11:02       ` Alexandre Oliva
2011-08-21 11:40         ` Jakub Jelinek
2011-08-22 14:45           ` Tom Tromey
2011-08-22 15:22             ` Jakub Jelinek
2011-08-23 19:52         ` Dodji Seketeli
2011-08-24 15:11           ` Tom Tromey
2011-09-12 22:07       ` Jason Merrill
2011-09-16  8:23         ` Dodji Seketeli
2011-09-17 22:01           ` Jason Merrill
2011-07-16 15:25     ` [PATCH 2/7] Generate virtual locations for tokens Dodji Seketeli
2011-08-09 15:30       ` Dodji Seketeli
2011-09-12 21:15         ` Jason Merrill
2011-09-14 10:01           ` Dodji Seketeli
2011-09-14 22:56             ` Jason Merrill
2011-09-18 13:44               ` Dodji Seketeli
2011-09-19 22:31                 ` Jason Merrill
2011-09-21 14:55                   ` Dodji Seketeli
2011-09-22 17:10                     ` Jason Merrill
2011-09-26 14:47                       ` Dodji Seketeli
2011-09-26 20:39                         ` Jason Merrill
2011-09-28  3:23                           ` Dodji Seketeli
2011-09-28 14:49                             ` Jason Merrill
2011-09-28 21:24                               ` Dodji Seketeli
2011-09-28 21:45                                 ` Jason Merrill
2011-09-29  5:49                                   ` Dodji Seketeli
2011-07-16 15:28     ` [PATCH 1/7] Linemap infrastructure for virtual locations Dodji Seketeli
2011-07-18 22:06       ` Jason Merrill
2011-07-19 10:47         ` Dodji Seketeli
2011-07-19 17:26           ` Jason Merrill
2011-07-19 18:03             ` Dodji Seketeli
2011-07-19 23:37       ` Jason Merrill
2011-07-30  6:20       ` Jason Merrill
2011-08-01 18:54         ` Dodji Seketeli
2011-08-01  4:42       ` Jason Merrill
2011-08-02  4:48       ` Jason Merrill
2011-08-04 15:28         ` Dodji Seketeli
2011-08-04 21:30           ` Jason Merrill
2011-08-05 17:12             ` Dodji Seketeli
2011-08-05 17:31               ` Jason Merrill
2011-08-09 14:56                 ` Dodji Seketeli
2011-08-19  8:46                   ` Jason Merrill
2011-08-19 14:43                     ` Tom Tromey
2011-09-01 10:37                     ` Dodji Seketeli
2011-09-07 19:26                       ` Jason Merrill
2011-09-08 12:41                         ` Dodji Seketeli
2011-09-09  7:45                           ` Jason Merrill
2011-09-09  8:57                           ` Jason Merrill
2011-07-16 15:34     ` [PATCH 7/7] Reduce memory waste due to non-power-of-2 allocs Dodji Seketeli
2011-09-12 22:25       ` Jason Merrill
2011-09-17 13:41         ` Dodji Seketeli
2011-09-17 22:22           ` Jason Merrill
2011-09-18 22:30             ` Dodji Seketeli
2011-09-19  6:51           ` Laurynas Biveinis
2011-07-16 16:47   ` [PATCH 0/7] Tracking locations of tokens resulting from macro expansion Tobias Burnus
2011-07-16 17:57     ` Dodji Seketeli
2011-10-17  9:58 [PATCH 0/6] " Dodji Seketeli
2011-10-17 10:25 ` [PATCH 1/6] Linemap infrastructure for virtual locations Dodji Seketeli
2011-10-17 19:53   ` Gerald Pfeifer
2011-10-17 20:44     ` Dodji Seketeli
2011-10-18  7:24       ` Gerald Pfeifer
2011-10-18  9:44         ` Dodji Seketeli

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=m3oc4bedph.fsf@redhat.com \
    --to=dodji@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdr@integrable-solutions.net \
    --cc=joseph@codesourcery.com \
    --cc=lopezibanez@gmail.com \
    --cc=tromey@redhat.com \
    /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).