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

refactor: eliminate many of the compiler warnings. #1858

Merged
merged 5 commits into from
Nov 2, 2022

Conversation

jpivarski
Copy link
Member

@jpivarski jpivarski commented Nov 1, 2022

I haven't done anything about the linker warnings (the whole build process is changing in #1778), and I wasn't sure what to do about warnings against aliasing arrays in the ForthMachine. That's kinda how the whole thing works...


📚 The documentation for this PR will be available at https://awkward-array.readthedocs.io/en/jpivarski-squash-compiler-warnings/ once Read the Docs has finished building 🔨

@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #1858 (c65ee0b) into main (173a6b6) will decrease coverage by 0.01%.
The diff coverage is n/a.

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

Additional details and impacted files
Impacted Files Coverage Δ
src/awkward/contents/indexedarray.py 76.60% <0.00%> (-0.19%) ⬇️
src/awkward/contents/recordarray.py 83.87% <0.00%> (-0.19%) ⬇️
src/awkward/_util.py 82.21% <0.00%> (-0.18%) ⬇️
src/awkward/contents/indexedoptionarray.py 88.90% <0.00%> (-0.16%) ⬇️
src/awkward/_connect/avro.py 87.17% <0.00%> (-0.14%) ⬇️
src/awkward/types/_awkward_datashape_parser.py 47.72% <0.00%> (-0.01%) ⬇️

@jpivarski
Copy link
Member Author

MacOS and Linux can't agree on whether the string format for int64_t is %lld (MacOS) or %ld (Linux). This is Linux (MacOS isn't complaining):

  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp: In member function ‘void awkward::ForthMachineOf<T, I>::print_number(T) [with T = long int; I = int]’:
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp:4301:16: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
   4301 |     printf("%lld ", num);
        |             ~~~^    ~~~
        |                |    |
        |                |    int64_t {aka long int}
        |                long long int
        |             %ld
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp: In instantiation of ‘void awkward::ForthMachineOf<T, I>::internal_run(bool, int64_t) [with T = int; I = int; int64_t = long int]’:
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp:4304:39:   required from here
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp:3824:27: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
   3824 |               printf("<%lld> ", stack_depth_);
        |                        ~~~^     ~~~~~~~~~~~~
        |                           |     |
        |                           |     int64_t {aka long int}
        |                           long long int
        |                        %ld
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp: In instantiation of ‘void awkward::ForthMachineOf<T, I>::internal_run(bool, int64_t) [with T = long int; I = int; int64_t = long int]’:
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp:4305:39:   required from here
  /home/runner/work/awkward/awkward/src/libawkward/forth/ForthMachine.cpp:3824:27: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
   3824 |               printf("<%lld> ", stack_depth_);
        |                        ~~~^     ~~~~~~~~~~~~
        |                           |     |
        |                           |     int64_t {aka long int}
        |                           long long int
        |                        %ld
  [ 96%] Built target awkward-objects

These are debugging print-outs for the ForthMachine, rarely used.

@jpivarski
Copy link
Member Author

Windows has a few complaints:

awkward_ListOffsetArray_argsort_strings.cpp
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xutility(240,43): warning C4244: 'argument': conversion from '__int64' to 'int', possible loss of data [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm(6926): message : see reference to function template instantiation 'decltype(auto) std::_Ref_fn<_Pr>::operator ()<__int64&,__int64&>(__int64 &,__int64 &)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _Pr=awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm(7495): message : see reference to function template instantiation '_BidIt *std::_Insertion_sort_unchecked<__int64*,std::_Ref_fn<_Pr>>(const _BidIt,const _BidIt,std::_Ref_fn<_Pr>)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _BidIt=__int64 *,
                _Pr=awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>
            ]
  D:\a\awkward\awkward\src\cpu-kernels\awkward_ListOffsetArray_argsort_strings.cpp(49): message : see reference to function template instantiation 'void std::stable_sort<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<_Ty>>>,awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>>(const _BidIt,const _BidIt,_Pr)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _Ty=int64_t,
                _BidIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int64_t>>>,
                _Pr=awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>
            ]
  D:\a\awkward\awkward\src\cpu-kernels\awkward_ListOffsetArray_argsort_strings.cpp(91): message : see reference to function template instantiation 'Error awkward_ListOffsetArray_argsort_strings_impl<true,true,true>(int64_t *,const int64_t *,int64_t,const char *,const int64_t *,const int64_t *)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xutility(240,43): warning C4244: 'argument': conversion from 'const _Ty' to 'int', possible loss of data [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _Ty=int64_t
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\xutility(5816): message : see reference to function template instantiation 'decltype(auto) std::_Ref_fn<_Pr>::operator ()<__int64&,const _Ty&>(__int64 &,const _Ty &)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _Pr=awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>,
                _Ty=__int64
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm(6435): message : see reference to function template instantiation '_FwdIt std::lower_bound<_BidIt,__int64,_Pr>(_FwdIt,const _FwdIt,const _Ty &,_Pr)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _FwdIt=__int64 *,
                _BidIt=__int64 *,
                _Pr=std::_Ref_fn<awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>>,
                _Ty=__int64
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm([645](https://github.com/scikit-hep/awkward/actions/runs/3373434075/jobs/5597998673#step:4:646)7): message : see reference to function template instantiation 'void std::_Buffered_inplace_merge_divide_and_conquer<_BidIt,_Pr>(_BidIt,_BidIt,_BidIt,__int64,__int64,__int64 *const ,const ptrdiff_t,_Pr)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _BidIt=__int64 *,
                _Pr=std::_Ref_fn<awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>>
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm([650](https://github.com/scikit-hep/awkward/actions/runs/3373434075/jobs/5597998673#step:4:651)2): message : see reference to function template instantiation 'void std::_Buffered_inplace_merge_unchecked_impl<_BidIt,_Pr>(_BidIt,_BidIt,_BidIt,__int64,__int64,__int64 *const ,const ptrdiff_t,_Pr)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _BidIt=__int64 *,
                _Pr=std::_Ref_fn<awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>>
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm(7483): message : see reference to function template instantiation 'void std::_Buffered_inplace_merge_unchecked<_BidIt,_Pr>(_BidIt,_BidIt,_BidIt,__int64,__int64,__int64 *const ,const ptrdiff_t,_Pr)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _BidIt=__int64 *,
                _Pr=std::_Ref_fn<awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>>
            ]
  C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\include\algorithm(7500): message : see reference to function template instantiation 'void std::_Stable_sort_unchecked<__int64*,std::_Ref_fn<_Pr>>(const _BidIt,const _BidIt,const __int64,__int64 *const ,const ptrdiff_t,std::_Ref_fn<_Pr>)' being compiled [D:\a\awkward\awkward\build\temp.win-amd64-cpython-38\Release\awkward-cpu-kernels-objects.vcxproj]
            with
            [
                _Pr=awkward_ListOffsetArray_argsort_strings_impl::<lambda_1f36786eccba502c48a687bbcb6c0be0>,
                _BidIt=__int64 *
            ]
    Generating Code...

@jpivarski
Copy link
Member Author

Yes, that did it!

And for the MacOS, Linux disagreement about %lld and %ld, how about if I just cast the number as "long long int" before string-formatting it?

@jpivarski
Copy link
Member Author

I don't see any warnings in CI. On my Mac, I see just one, and on Linux, none.

@ianna, could you review this and make sure I'm not bulldozing over something important?

@jpivarski jpivarski requested a review from ianna November 1, 2022 23:23
@jpivarski
Copy link
Member Author

The casts don't prevent the problems the warnings are warning about, but they do make type assumptions explicit in the code, which would make it easier to debug the kinds of errors the warnings are warning about, if that ever happens (integer overflows and stuff).

Copy link
Collaborator

@ianna ianna left a comment

Choose a reason for hiding this comment

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

@jpivarski - Looks great! There are no compiler warnings on my Mac! Thanks!

I'm approving it - with a few comments about the removed variable names. I think, it would be nice to tidy up the kernels (if they are still in use) and the ForthOutputBuffer APIs. I'll leave it up to you.

The Regular layout builder example with an unbalanced begin and end list looks odd to me.

include/awkward/python/content.h Outdated Show resolved Hide resolved
src/cpu-kernels/awkward_NumpyArray_rearrange_shifted.cpp Outdated Show resolved Hide resolved
src/cpu-kernels/awkward_unique_ranges.cpp Outdated Show resolved Hide resolved
src/libawkward/builder/BoolBuilder.cpp Show resolved Hide resolved
src/libawkward/forth/ForthMachine.cpp Outdated Show resolved Hide resolved
src/libawkward/forth/ForthOutputBuffer.cpp Outdated Show resolved Hide resolved
tests-cpp/test_1494-layout-builder.cpp Show resolved Hide resolved
@jpivarski
Copy link
Member Author

Okay, all of the cases in which an argument is not needed is now documented with the argument name in a comment (/* argument_name */). Some of these cases can be cleaned up with a refactoring that removes this argument completely. In other cases, the argument should still be there for symmetry or because we're adhering to an API from another library (RapidJSON).

@jpivarski jpivarski merged commit 87049ac into main Nov 2, 2022
@jpivarski jpivarski deleted the jpivarski/squash-compiler-warnings branch November 2, 2022 15:18
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