unum-cloud / usearch

Fast Open-Source Search & Clustering engine × for Vectors & 🔜 Strings × in C++, C, Python, JavaScript, Rust, Java, Objective-C, Swift, C#, GoLang, and Wolfram 🔍
https://unum-cloud.github.io/usearch/
Apache License 2.0
2.27k stars 143 forks source link

Do not use `#pragma region` if not supported by the compiler #386

Closed mbautin closed 6 months ago

ashvardanian commented 7 months ago

Thanks for the PR! Just to clarify, which compilers don't support that pragma?

mbautin commented 7 months ago

I am getting these errors with GCC 11 (is it still supported by usearch?)

[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2024: error: ignoring '#pragma region Adjusting' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2024 | #pragma region Adjusting Configuration
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2117: error: ignoring '#pragma endregion ' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2117 | #pragma endregion
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2119: error: ignoring '#pragma region Construction' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2119 | #pragma region Construction and Search
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2560: error: ignoring '#pragma endregion ' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2560 | #pragma endregion
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2562: error: ignoring '#pragma region Metadata' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2562 | #pragma region Metadata
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2666: error: ignoring '#pragma endregion ' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2666 | #pragma endregion
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2668: error: ignoring '#pragma region Serialization' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2668 | #pragma region Serialization
[2024-04-04T20:49:18.157Z]       |
[2024-04-04T20:49:18.157Z] ../../src/inline-thirdparty/usearch/usearch/index.hpp:2959: error: ignoring '#pragma endregion ' [-Werror=unknown-pragmas]
[2024-04-04T20:49:18.157Z]  2959 | #pragma endregion
ashvardanian commented 7 months ago

Yep, it is, but I believe there is a cleaner way to avoid this warning. You can set a push-options pragma on top of the file, and a pragma-pop, asking to ignore "unknown pragmas". That may be a less repetitive solution, assuming that region annotation is also used in SimSIMD and StringZilla 🤷‍♂️

mbautin commented 7 months ago

Unfortunately, the following does not work for me:

#pragma GCC diagnostic ignored "-Wunknown-pragmas"

I have to add -Wno-unknown-pragmas on the command line. Our codebase is being compiled with -Werror. This might be an issue for anyone else using GCC 11+ (however, I have not tested with GCC 12 yet).

ashvardanian commented 6 months ago

It's supported on GCC 13 and newer, so I'll patch the condition and merge 🤗

There are only 4 regions in the usearch/index.hpp, but if we include the submodules the number multiplies to 66. Any chance there is a cleaner way to define this pragma and backport it to older GCC versions, @mbautin?

ashvardanian commented 6 months ago

I've tried using the _Pragma variant, but I believe that overcomplicates things.

// The `#pragma region` and `#pragma endregion` are not supported by GCC 12 and older.
// But they are supported by GCC 13, all recent Clang versions, and MSVC.
#if defined(__GNUC__) && ((__GNUC__ > 12) || (__GNUC__ == 12 && __GNUC_MINOR__ >= 0))
#define USE_PRAGMA_REGION
#elif defined(__clang__) || defined(_MSC_VER)
#define USE_PRAGMA_REGION
#endif
#ifdef USE_PRAGMA_REGION
#define PRAGMA_REGION(name) _Pragma(#name)
#define PRAGMA_ENDREGION(name) _Pragma(#name)
#else
#define PRAGMA_REGION(name)
#define PRAGMA_ENDREGION(name)
#endif

Will revert to your variant, @mbautin 🤗