Re: shadow variables - pg15 edition
Justin Pryzby <pryzby@telsasoft.com>
From: Justin Pryzby <pryzby@telsasoft.com>
To: David Rowley <dgrowleyml@gmail.com>
Cc: pgsql-hackers@postgresql.org, Tomas Vondra <tomas.vondra@postgresql.org>, Peter Smith <smithpb2250@gmail.com>
Date: 2022-08-30T05:44:41Z
Lists: pgsql-hackers
Attachments
- v5.txt (text/plain)
On Wed, Aug 24, 2022 at 10:47:31PM +1200, David Rowley wrote: > I really think #2s should be done last. I'm not as comfortable with > the renaming and we might want to discuss tactics on that. We could > either opt to rename the shadowed or shadowing variable, or both. If > we rename the shadowing variable, then pending patches or forward > patches could use the wrong variable. If we rename the shadowed > variable then it's not impossible that backpatching could go wrong > where the new code intends to reference the outer variable using the > newly named variable, but when that's backpatched it uses the variable > with the same name in the inner scope. Renaming both would make the > problem more obvious. The most *likely* outcome of renaming the *outer* variable is that *every* cherry-pick involving that variable would fails to compile, which is an *obvious* failure (good) but also kind of annoying if it could've worked fine if it weren't renamed. I think most of the renames should be applied to the inner var, because it's of narrower scope, and more likely to cause a conflict (good) rather than appearing to apply cleanly but then misbehave. But it seems reasonable to consider renaming both if the inner scope is longer than a handful of lines. > Would you be able to write a patch for #4. I'll do #5 now. You could > do a draft patch for #2 as well, but I think it should be committed > last, if we decide it's a good move to make. It may be worth having > the discussion about if we actually want to run > -Wshadow=compatible-local as a standard build flag before we rename > anything. I'm afraid the discussion about default flags would distract from fixing the individual warnings, which itself preclude usability of the flag by individual developers, or buildfarm, even as a local setting. It can't be enabled until *all* the shadows are gone, due to -Werror on the buildfarm and cirrusci. Unless perhaps we used -Wno-error=shadow. I suppose we're only talking about enabling it for gcc? The biggest benefit is if we fix *all* the local shadow vars, since that allows someone to make use of the option, and thereby avoiding future such issues. Enabling the option could conceivably avoid issues cherry-picking into back branch - if an inner var is re-introduced during conflict resolution, then a new warning would be issued, and hopefully the developer would look more closely. Would you check if any of these changes are good enough ? -- Justin
Commits
-
Fix shadow variable in postgres.c
- 4574eb9d38c6 16.0 landed
-
Add -Wshadow=compatible-local to the standard compilation flags
- 0fe954c28584 16.0 landed
-
Fix final warnings produced by -Wshadow=compatible-local
- cd4e8caaa0eb 16.0 landed
-
Fix final compiler warning produced by -Wshadow=compatible-local
- d8df67bb1ad9 16.0 landed
-
Add optional parameter to PG_TRY() macros
- 112f0225dbfe 16.0 landed
-
Small refactor to get rid of -Wshadow=compatible-local warning
- d389487525bc 16.0 landed
-
More -Wshadow=compatible-local warning fixes
- 3e0fff2e6888 16.0 landed
-
Further -Wshadow=compatible-local warning fixes
- f959bf9a5b9c 16.0 landed
-
Further reduce warnings with -Wshadow=compatible-local
- 421892a192b8 16.0 landed
-
Reduce warnings with -Wshadow=compatible-local builds
- 92fce4e1eda9 16.0 landed
-
Remove shadowed local variables that are new in v15
- 24f457aa2b70 15.0 landed
- f01592f91577 16.0 landed