Skip to content

Commit

Permalink
remove mention of static_assert compilation error (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum authored Sep 20, 2024
1 parent 65ed051 commit aa0b20e
Showing 1 changed file with 0 additions and 60 deletions.
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.

0 comments on commit aa0b20e

Please sign in to comment.