Enable `-fstrict-overflow`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- PR マージ指標
- PR 指標を取得中
説明
At the moment we compile releases with -fwrapv which makes the code a bit safer, but disables certain optimizations. From the GCC docs:
This option instructs the compiler to assume that signed arithmetic overflow of addition, subtraction and multiplication wraps around using twos-complement representation. This flag enables some optimizations and disables others.
My experiments with running sanitisers seem to suggest that we are nearly already ready for -fno-wrapv (or -fstrict-overflow in general). Doing so could lead to quite a few speedups, but we would need to be more careful with the code we write.
It might be worthwhile to get a few benchmarks.
(To be extra precise, we give -fwrapv for clang and gcc for any build that doesn't get --with-pydebug.)
Pitch
My plan right now is to adapt the build system so that only the modules that need it are build with -fwrapv, and the rest can be build with -fstrict-overflow.
We already have config machinery that can add specific CFLAGS for specific modules only.
Perhaps the whole thing can be gated behind a configure flag, like --with-strict-overflow.
If everything goes well, and this improves performance we can consider adding this functionality to one of the standard optimization options.
We can also work on making more modules -fstrict-overflow safe.
Previous discussion
@markshannon @ericsnowcurrently
Brought up on https://github.com/faster-cpython/ideas/issues/458 and inspired by https://github.com/python/cpython/issues/96678
Some previous issues around -fwrapv:
- https://bugs.python.org/issue11149
- https://bugs.python.org/issue1621
- https://bugs.python.org/issue1608
I'm sure there are more.
Progress so far
As far as is currently known, the three remaining modules that rely on defined integer overflow are fixed by:
_struct: https://github.com/python/cpython/pull/96739audioop: https://github.com/python/cpython/pull/96923_ctypes: https://github.com/python/cpython/pull/96925
Linked PRs
- gh-96823
- gh-139595
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
モジュール固有の CFLAGS を追加するビルドシステムの設定機構から始め、続いて gh-96823 と gh-139595 にリンクされた作業を確認してください。提案されている変更は、対象となるモジュール向けの configure で切り替えられる strict-overflow ビルドであり、残りの overflow 依存モジュールは安全に処理し、ベンチマークでパフォーマンスを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c
- 領域
- build-system, compilers, performance
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100