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

Fix type mismatch warnings #839

Merged
merged 8 commits into from
Jan 10, 2025

Conversation

mhucka
Copy link
Member

@mhucka mhucka commented Jan 4, 2025

Many files produced many type mismatch warnings with both clang 17 and gcc 14 on a Debian 6.10.11 x86_64 system. This commit fixes almost all the ones I'm seeing in the TFQ code base.

Some other warnings still arise in other code and modules. Those warnings don't appear to be things we can easily work around short of creating a lot of patch files (at significant cost in time and testing). For those, I'm currently relying on setting compiler options (e.g., -Wno-unused-function for warnings about unused functions) narrowed in scope to the problematic package using Bazel's --per_file_copt and --host_per_file_copt flags. Those flags are not in this PR.

Note: this PR should be applied after PR #837.

mhucka added 3 commits January 4, 2025 22:22
Many files produced many type mismatch warnings with both clang 17 and
gcc 14 on a Debian 6.10.11 x86_64 system. This commit fixes almost all
the ones I'm seeing in the TFQ code base.

Some other warnings still arise in other code and modules. Those
warnings don't appear to be things we can easily work around short of
creating a lot of patch files (at significant cost in time and
testing). For those, I'm currently relying on setting compiler options
(e.g., `-Wno-unused-function` for warnings about unused functions)
narrowed in scope to the problematic package using Bazel's
`--per_file_copt` and `--host_per_file_copt` flags. Those flags are
not in this commit; they need to be made part of the TFQ
`configure.sh` script.
@mhucka mhucka marked this pull request as ready for review January 5, 2025 01:54
@mhucka mhucka added kind/chore Maintenance & housekeeping tasks area/code-health Concerns stability, quality, technical debt, etc. labels Jan 5, 2025
@mhucka mhucka self-assigned this Jan 5, 2025
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

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

Looks good. Hopefully this gets rid of some of the type warning headaches. It does seem like our use of size_t vs int in loops now will be more inconsistent overall, but if that gets us fewer warnings, I guess it's a step in the right direction.

@@ -146,7 +146,7 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel {
auto DoWork2 = [&](int start, int end) {
for (int i = start; i < end; i++) {
for (int j = 0; j < n_symbols; j++) {
for (int k = 0; k < output_results.at(i).at(j).size(); k++) {
for (size_t k = 0; k < output_results.at(i).at(j).size(); k++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do just k and not i, j as well ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that's because k is the only one being compared to a .size() value; i and j are used as indexes.

@@ -146,7 +146,7 @@ class TfqPsWeightsFromSymbolOp : public tensorflow::OpKernel {
auto DoWork2 = [&](int start, int end) {
for (int i = start; i < end; i++) {
for (int j = 0; j < n_symbols; j++) {
for (int k = 0; k < output_results.at(i).at(j).size(); k++) {
for (size_t k = 0; k < output_results.at(i).at(j).size(); k++) {
output_tensor(i, j, k) = output_results.at(i).at(j).at(k);
}
for (int k = output_results.at(i).at(j).size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree this one looks inconsistent. It's because in this case, the value of k is being compared to largest_single_symbol on the next line, and that variable is an int.

The weird thing is k is initialized by setting its value to the output of size(), and yet the compiler isn't complaining about that part. I don't have a good explanation for that.

Although the compiler didn't flag them, a couple of declarations
that were changed to size_t in a previous commit should probably have
const declarations, to be consistent with other changes in the same
function.
mhucka added 3 commits January 9, 2025 16:50
One of the `size_t` → `int` changes was wrong and led to a test
failure.

I would prefer to edit the commit itself; however, that would require
force-pushing to the TFQ repo, and I'm not sure if that will break the
code review comments in the PR in GitHub. So I'm making the change in
a separate commit.
@mhucka mhucka merged commit e28d106 into tensorflow:master Jan 10, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-health Concerns stability, quality, technical debt, etc. kind/chore Maintenance & housekeeping tasks
Development

Successfully merging this pull request may close these issues.

2 participants