Thread: useless assignment pointer argument

useless assignment pointer argument

From
Gaetano Mendola
Date:
Hi,
in the following spots:

src/backend/commands/explain.c:1692
src/backend/commands/explain.c:1874
src/backend/commands/explain.c:1986

there is the following assignment: 

   ancestors = list_delete_first(ancestors);

but it has no effect at all being that a function parameter and not used anymore after the assignment itself.

Re: useless assignment pointer argument

From
Andres Freund
Date:
On 2015-05-28 20:14:33 +0000, Gaetano Mendola wrote:
> src/backend/commands/explain.c:1692
> src/backend/commands/explain.c:1874
> src/backend/commands/explain.c:1986
> 
> there is the following assignment:
> 
>    ancestors = list_delete_first(ancestors);
> 
> but it has no effect at all being that a function parameter and not used
> anymore after the assignment itself.

So? It costs little to nothing, and it'll make it much less likely that
a stale version of 'ancestors' is used when the code is expanded.

Greetings,

Andres Freund



Re: useless assignment pointer argument

From
Gaetano Mendola
Date:
<div dir="ltr">If the compiler is good the assignment is elided indeed, that's not what I meant to point out.<br
/></div><br/><div class="gmail_quote"><div dir="ltr">On Thu, 28 May 2015 at 22:17 Andres Freund <<a
href="mailto:andres@anarazel.de">andres@anarazel.de</a>>wrote:<br /></div><blockquote class="gmail_quote"
style="margin:00 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2015-05-28 20:14:33 +0000, Gaetano Mendola
wrote:<br/> > src/backend/commands/explain.c:1692<br /> > src/backend/commands/explain.c:1874<br /> >
src/backend/commands/explain.c:1986<br/> ><br /> > there is the following assignment:<br /> ><br /> >   
ancestors= list_delete_first(ancestors);<br /> ><br /> > but it has no effect at all being that a function
parameterand not used<br /> > anymore after the assignment itself.<br /><br /> So? It costs little to nothing, and
it'llmake it much less likely that<br /> a stale version of 'ancestors' is used when the code is expanded.<br /><br />
Greetings,<br/><br /> Andres Freund<br /></blockquote></div> 

Re: useless assignment pointer argument

From
Tom Lane
Date:
Andres Freund <andres@anarazel.de> writes:
> On 2015-05-28 20:14:33 +0000, Gaetano Mendola wrote:
>> src/backend/commands/explain.c:1692
>> src/backend/commands/explain.c:1874
>> src/backend/commands/explain.c:1986
>> 
>> there is the following assignment:
>> 
>> ancestors = list_delete_first(ancestors);
>> 
>> but it has no effect at all being that a function parameter and not used
>> anymore after the assignment itself.

> So? It costs little to nothing, and it'll make it much less likely that
> a stale version of 'ancestors' is used when the code is expanded.

It's completely mistaken to imagine that the statement has no effect:
it does change the underlying List structure, so removing it would be
wrong.

It's true that we could, today, write it as
(void) list_delete_first(ancestors);

but this is not any more clear IMO, and it would fail if the code were
ever changed so that these functions did use the ancestors list after
the point of popping the context they pushed for their children.  That
risk outweighs any argument about how deleting the assignment would
quiet some tool or other.
        regards, tom lane