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 mention of static_assert compilation error #76

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,64 +239,4 @@ slower than a compiled version, so you should default to installing the wheel in
CI instead of compiling Cython, which can take up to a few minutes on some CI
runners.

### Cython compilation errors arising from `static_assert`

This error arises from a limitation in Cython that exposes a CPython
implementation detail. Under clang, the issue manifests in error messages like
the following example, generated by building scikit-learn with a C99 compilation
environment:

```
In file included from sklearn/__check_build/_check_build.cpython-313t-darwin.so.p/sklearn/__check_build/_check_build.pyx.c:4315:
In file included from /path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_frame.h:13:
/path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_code.h:537:15: error: expected parameter declarator
static_assert(COLD_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
^
/path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_backoff.h:125:33: note: expanded from macro 'COLD_EXIT_INITIAL_VALUE'
#define COLD_EXIT_INITIAL_VALUE 64
^
In file included from sklearn/__check_build/_check_build.cpython-313t-darwin.so.p/sklearn/__check_build/_check_build.pyx.c:4315:
In file included from /path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_frame.h:13:
/path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_code.h:537:15: error: expected ')'
/path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_backoff.h:125:33: note: expanded from macro 'COLD_EXIT_INITIAL_VALUE'
#define COLD_EXIT_INITIAL_VALUE 64
^
/path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_code.h:537:14: note: to match this '('
static_assert(COLD_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
^
/path/to/python/3.13.0b3t/include/python3.13t/internal/pycore_code.h:537:1: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
static_assert(COLD_EXIT_INITIAL_VALUE > ADAPTIVE_COOLDOWN_VALUE,
^
int
```

Free-threading support in Cython relies CPython internals. In particular, Cython
will generate code that in some situations includes an internal CPython header,
`pycore_frame.h`. This header, in turn, includes another header `pycore_code.h`
that makes use of `static_assert`, a construct defined in the C11 standard. This
is problematic for a compiler assuming compliance with C99.

In practice we have found the easiest way to fix this is to update the standard
used to build C code to either C11 or C17. In the meson build configuration for
a simple C project, this looks like:

```meson
project(
'my-project',
'c',
default_options: [
'c_std=c17',
],
)
```

Note that C17 corrected defects, removed optional requirements, and did not add
any new features compared with C11, so requiring C11 support may be more onerous than
C17. The CPython codebase currently assumes a compiler with at least partial C11
support, and we have found for all major compilers (including MSVC) that
updating the assumed C standard is not a big problem as of mid-2024. There are
some C11 features that MSVC and other compilers are missing, so please open an
issue if this ends up being a big problem for your project or a subset of your
userbase.

[^1]: This feature is not correctly working on `lldb` after CPython 3.12.