Skip to content

Support error handling without exceptions #619

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

michaelbautin
Copy link
Collaborator

@michaelbautin michaelbautin commented Mar 26, 2025

Adding support for disabling exceptions

Adding a mode of error handling that does not rely on C++ exceptions,
with Abseil-like Status and StatusOr return types (but not adding a
dependency on Abseil). The old exceptions-based API is still available,
and the new functions are suffixed with "NoExceptions".

Refactoring the CMake build system. Organizing examples and tests and
reducing repetition. Adding the HNSWLIB_ENABLE_EXCEPTIONS option (ON by
default). Exceptions are also enabled when building Python bindings, and
in a few examples/tests where the code currently relies on exception
handling, even if HNSWLIB_ENABLE_EXCEPTIONS is set to OFF.

Adding ctest support. The only tests not supported by ctest are
test_updates invoked with and without the "update" argument, because
that requires installing numpy and running a data generation script and
doing that from a CMake test might be controversial. Those tests are
still run as part of GitHub Actions CI.

Enabling sanitizer support using ENABLE_ASAN / ENABLE_UBSAN /
ENABLE_TSAN / ENABLE_MSAN CMake options. Adding a combined ASAN/UBSAN
build type to the C++ test matrix in GitHub Actions in non-Windows
builds. Also adding Clang compiler on Ubuntu to the build matrix.

Making sure that assertions are enabled during tests. Using the
RelWithDebInfo build type and customizing it to remove the NDEBUG flag.
Also removing the default /EHsc flag when building with MSVC and instead
enabling exceptions when needed.

Fixing race conditions when accessing random number generators and
distributions from multiple threads in multiThreadLoad_test. These race
conditions were caught using ASAN/UBSAN.

getnamo added a commit to getnamo/Llama-Unreal that referenced this pull request Apr 12, 2025
@yurymalkov yurymalkov changed the base branch from master to develop April 20, 2025 23:47
@yurymalkov yurymalkov closed this Apr 21, 2025
@yurymalkov yurymalkov reopened this Apr 21, 2025
@dyashuni
Copy link
Contributor

@michaelbautin Looks good!

I have some concerns regarding the use of auto in the C++ examples. For less experienced users, this might make the code harder to understand. Could you please keep the original types, even if they are a bit long?

@michaelbautin
Copy link
Collaborator Author

@dyashuni @yurymalkov : thanks for the review and for validating the approach! I will clean up the code / tests, restore the explicit types, and update the PR.

@michaelbautin michaelbautin force-pushed the allow_avoiding_exceptions branch from d8ee83b to 733751d Compare May 29, 2025 02:34
@michaelbautin
Copy link
Collaborator Author

@yurymalkov , @dyashuni : I've updated the PR, addressed the review comments, added ctest support and ran the tests locally. Could you please trigger CI/CD again on this PR?

@michaelbautin michaelbautin force-pushed the allow_avoiding_exceptions branch from 194da62 to 137581c Compare May 30, 2025 22:33
@michaelbautin michaelbautin force-pushed the allow_avoiding_exceptions branch from 8003319 to 619f6ca Compare June 7, 2025 02:52
@michaelbautin
Copy link
Collaborator Author

@yurymalkov , @dyashuni : I think the PR is ready for both of you to take another look. The test matrix has been significantly enhanced and the tests are passing.

@michaelbautin michaelbautin force-pushed the allow_avoiding_exceptions branch from 619f6ca to f0047b4 Compare June 9, 2025 20:29
Adding a mode of error handling that does not rely on C++ exceptions,
with Abseil-like Status and StatusOr return types (but not adding a
dependency on Abseil). The old exceptions-based API is still available,
and the new functions are suffixed with "NoExceptions".

Refactoring the CMake build system. Organizing examples and tests and
reducing repetition. Adding the HNSWLIB_ENABLE_EXCEPTIONS option (ON by
default). Exceptions are also enabled when building Python bindings, and
in a few examples/tests where the code currently relies on exception
handling, even if HNSWLIB_ENABLE_EXCEPTIONS is set to OFF.

Adding ctest support. The only tests not supported by ctest are
test_updates invoked with and without the "update" argument, because
that requires installing numpy and running a data generation script and
doing that from a CMake test might be controversial. Those tests are
still run as part of GitHub Actions CI.

Enabling sanitizer support using ENABLE_ASAN / ENABLE_UBSAN /
ENABLE_TSAN / ENABLE_MSAN CMake options. Adding a combined ASAN/UBSAN
build type to the C++ test matrix in GitHub Actions in non-Windows
builds. Also adding Clang compiler on Ubuntu to the build matrix.

Making sure that assertions are enabled during tests. Using the
RelWithDebInfo build type and customizing it to remove the NDEBUG flag.
Also removing the default /EHsc flag when building with MSVC and instead
enabling exceptions when needed.

Fixing race conditions when accessing random number generators and
distributions from multiple threads in multiThreadLoad_test. These race
conditions were caught using ASAN/UBSAN.
@michaelbautin michaelbautin force-pushed the allow_avoiding_exceptions branch from f0047b4 to aca90ff Compare June 9, 2025 20:49
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.

3 participants