Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused variables #112

Merged
merged 1 commit into from
Apr 20, 2022
Merged

Conversation

marshallward
Copy link
Member

This patch removes any unused variables detected by -Wunused-variables
in GCC.

This may include variables which are referenced in commented "zombie
code". In some cases, the variables were preserved in comments, but no
in all cases. If the zombie code is restored, it should be possible to
reconstruct the original declaration. (All known cases were simple
scalars, such as loop indices).

In one case, a variable was conditionally used within a preprocessor
#ifdef __DO_SAFETY_CHECKS__ block. This patch moves the declaration
into another #ifdef block, but perhaps it is preferable to remove the
block.

Certain documentation variables such as mdl, which typically contain
the function name, have been removed if unused.

The strongest motivation for this patch is to allow us to enable the
-Wall flag, which includes unused variables, and will strengthen our
ability to detect potential errors in the codebase.

@codecov
Copy link

codecov bot commented Apr 15, 2022

Codecov Report

Merging #112 (a3f89d7) into dev/gfdl (684878e) will increase coverage by 0.00%.
The diff coverage is 37.77%.

❗ Current head a3f89d7 differs from pull request most recent head 48ae48a. Consider uploading reports for the commit 48ae48a to get more accurate results

@@            Coverage Diff            @@
##           dev/gfdl     #112   +/-   ##
=========================================
  Coverage     28.76%   28.77%           
=========================================
  Files           248      248           
  Lines         72976    72954   -22     
=========================================
- Hits          20995    20991    -4     
+ Misses        51981    51963   -18     
Impacted Files Coverage Δ
...g_src/drivers/solo_driver/MESO_surface_forcing.F90 0.00% <ø> (ø)
config_src/drivers/solo_driver/MOM_driver.F90 67.33% <ø> (ø)
...c/external/GFDL_ocean_BGC/generic_tracer_utils.F90 0.00% <ø> (ø)
config_src/infra/FMS1/MOM_couplertype_infra.F90 3.37% <ø> (ø)
config_src/infra/FMS1/MOM_io_infra.F90 20.59% <ø> (ø)
src/ALE/MOM_ALE.F90 34.77% <0.00%> (ø)
src/ALE/MOM_hybgen_regrid.F90 0.00% <0.00%> (ø)
src/ALE/MOM_hybgen_remap.F90 0.00% <ø> (ø)
src/ALE/MOM_hybgen_unmix.F90 0.00% <ø> (ø)
src/ALE/coord_slight.F90 0.00% <0.00%> (ø)
... and 133 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 684878e...48ae48a. Read the comment docs.

@@ -240,7 +239,7 @@ subroutine edge_values_explicit_h4( N, h, u, edge_val, h_neglect, answers_2018 )
real, dimension(4) :: dz ! A temporary array of limited layer thicknesses [H]
real, dimension(4) :: u_tmp ! A temporary array of cell average properties [A]
real, parameter :: C1_12 = 1.0 / 12.0
real :: dx, xavg ! Differences and averages of successive values of x [H]
real :: dx ! Differences and averages of successive values of x [H]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment on this line and below at lines 408 and 715 are now inconsistent with the declaration of a single variable.

integer :: k, k_bot_min, k_top_max !< k-indices, min and max for bottom and top, respectively
integer :: k_bot_max, k_top_min !< k-indices, max and min for bottom and top, respectively
integer :: k_bot_diff, k_top_diff !< different between left and right k-indices for bottom and top, respectively
integer :: k, k_bot_min !< k-indices, min and max for bottom and top, respectively
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k_top_max, k_top_min, and k_top_diff are in commented out code, and are reasonably described in the comments. Even though they are not used yet, perhaps they should be retained in comments.

Copy link
Member

@Hallberg-NOAA Hallberg-NOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for eliminating the large number of unused variables in the MOM6 code. I have examined all of these changes, and I think that this will be ready to go as soon as 3 minor comments (listed separately) have been addressed.

This patch removes any unused variables detected by -Wunused-variables
in GCC.

This may include variables which are referenced in commented "zombie
code".  In some cases, the variables were preserved in comments, but not
in all cases.  If the zombie code is restored, it should be possible to
reconstruct the original declaration.  (All known cases were simple
scalars, such as loop indices).

In one case, a variable was conditionally used within a preprocessor
`#ifdef __DO_SAFETY_CHECKS__` block.  This patch moves the declaration
into another `#ifdef` block, but perhaps it is preferable to remove the
block.

Certain documentation variables such as `mdl`, which typically contain
the function name, have been removed if unused.

The strongest motivation for this patch is to allow us to enable the
`-Wall` flag, which includes unused variables, and will strengthen our
ability to detect potential errors in the codebase.
@marshallward
Copy link
Member Author

I've made the changes recommended by @Hallberg-NOAA, and have also re-added the variable used by @ashao.

Copy link
Member

@Hallberg-NOAA Hallberg-NOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for eliminating all of these unused variables and moving around the content in comments as appropriate.

This PR should be accepted and merged in as soon as it passes the pipeline testing.

@Hallberg-NOAA
Copy link
Member

This PR passed the pipeline testing at https://gitlab.gfdl.noaa.gov/ogrp/MOM6/-/jobs/77063, but with some irregularities in the units of a variable in the available_diags file stemming from another PR that was accepted earlier today. I am accepting this PR, but will look into that other issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants