python / python/cpython

[Tool: c-analyzer] Unexpected Intermediate Error When the Tool Fails

オープン
#116,828 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

When the c-analyzer tool (Tools/c-analyzer) fails due to an unsupported C global variable, it is also printing a traceback that indicates a bug somewhere in the tool.

(expand for an example)

From the CI check in gh-116413:

python3.12 ./Tools/c-analyzer/check-c-globals.py \
	--format summary \
	--traceback
analyzing files...
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ....
checking analysis results...
Traceback (most recent call last):

-------------------------
  File "/home/runner/work/cpython/cpython/./Tools/c-analyzer/check-c-globals.py", line 39, in <module>
    main(cmd, cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 498, in main

Non-constant global variables are generally not supported
in the CPython repo.  We use a tool to analyze the C code
and report if any unsupported globals are found.  The tool
may be run manually with:

  ./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]

Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).

If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code.  If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.

If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules).  In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided.  If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).

    run_cmd(**cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 1[59](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:60), in cmd_check
    c_analyzer.cmd_check(
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__main__.py", line 331, in cmd_check
    for data, failure in _check_all(decls, checks, failfast=failfast):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 94, in check_all
    for data, failure in check(analysis):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 411, in check_globals
    ignored = read_ignored()
              ^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 124, in read_ignored
    _IGNORED.update(_datafiles.read_ignored(NEED_FIX_FILE, relroot=REPO_ROOT))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line [93](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:94), in read_ignored
    return dict(_iter_ignored(infile, relroot))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line [107](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:108), in _iter_ignored
    varid = _info.DeclID.from_row(varidinfo)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/info.py", line 207, in from_row
    return cls(*row)
           ^^^^^^^^^
TypeError: DeclID.__new__() missing 3 required positional arguments: 'filename', 'funcname', and 'name'
make: *** [Makefile:3[16](https://github.com/python/cpython/actions/runs/8281492333/job/22660094475#step:16:17)1: check-c-globals] Error 1
Error: Process completed with exit code 2.
(expand for another example)

From the CI check in gh-116413:

python3.12 ./Tools/c-analyzer/check-c-globals.py \
	--format summary \
	--traceback
analyzing files...
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....
..... ..... ..... ..... .....

..... ....
checking analysis results...
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython/./Tools/c-analyzer/check-c-globals.py", line 39, in <module>

    main(cmd, cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 498, in main
-------------------------
    run_cmd(**cmd_kwargs)
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/__main__.py", line 1[59](https://github.com/python/cpython/actions/runs/8280034808/job/22655683079#step:16:60), in cmd_check
    c_analyzer.cmd_check(
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__main__.py", line 331, in cmd_check
    for data, failure in _check_all(decls, checks, failfast=failfast):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/__init__.py", line 94, in check_all
    for data, failure in check(analysis):
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 411, in check_globals
    ignored = read_ignored()
              ^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/cpython/_analyzer.py", line 124, in read_ignored
    _IGNORED.update(_datafiles.read_ignored(NEED_FIX_FILE, relroot=REPO_ROOT))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line 93, in read_ignored
    return dict(_iter_ignored(infile, relroot))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_analyzer/datafiles.py", line 107, in _iter_ignored
    varid = _info.DeclID.from_row(varidinfo)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/cpython/cpython/Tools/c-analyzer/c_parser/info.py", line 207, in from_row
    return cls(*row)
           ^^^^^^^^^
TypeError: DeclID.__new__() missing 3 required positional arguments: 'filename', 'funcname', and 'name'

Non-constant global variables are generally not supported
in the CPython repo.  We use a tool to analyze the C code
and report if any unsupported globals are found.  The tool
may be run manually with:

  ./python Tools/c-analyzer/check-c-globals.py --format summary [FILE]

Occasionally the tool is unable to parse updated code.
If this happens then add the file to the "EXCLUDED" list
in Tools/c-analyzer/cpython/_parser.py and create a new
issue for fixing the tool (and CC ericsnowcurrently
on the issue).

If the tool reports an unsupported global variable and
it is actually const (and thus supported) then first try
fixing the declaration appropriately in the code.  If that
doesn't work then add the variable to the "should be const"
section of Tools/c-analyzer/cpython/ignored.tsv.

If the tool otherwise reports an unsupported global variable
then first try to make it non-global, possibly adding to
PyInterpreterState (for core code) or module state (for
extension modules).  In an emergency, you can add the
variable to Tools/c-analyzer/cpython/globals-to-fix.tsv
to get CI passing, but doing so should be avoided.  If
this course it taken, be sure to create an issue for
eliminating the global (and CC ericsnowcurrently).

make: *** [Makefile:3[16](https://github.com/python/cpython/actions/runs/8280034808/job/22655683079#step:16:17)1: check-c-globals] Error 1
Error: Process completed with exit code 2.

The examples demonstrate that the traceback is coming from a different thread than the expected error message.

Note that, in the examples, the tool doesn't report the unsupported globals it found, like it normally would.

Related: gh-116826

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Tools/c-analyzer/c_analyzer/datafiles.py、c_parser/info.py、c-python/_analyzer.py から始め、check-c-globals.py コマンドと DeclID.from_row() の traceback を追ってください。示されているコマンドで失敗を再現してください。完了の条件は、無関係な中間 traceback なしに、サポートされていない globals が通常どおり報告されることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
ci-cd, tooling
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。