Place CPython thread types in their defining header’s Go file - #925
Conversation
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
There was a problem hiding this comment.
Review summary
The core fix in cl/compile.go is small, well-targeted, and follows the existing idioms in the cl/ package (IsCursorDefinition() == 0, Definition(), IsNull() == 0, clang.PresumedFile). For a forward-declared class/struct it resolves the file/package from the definition's location instead of the forward declaration's location, which correctly fixes the misattribution the generated fixture change (X_PyTssT moving from pythread.go to cpython-pythread.go) demonstrates. The null-definition guard is correct and the change is behaviorally conservative. Build passes.
No security concerns. The go.mod/go.sum pruning in tool/_testcpp/llvm-22.1.8-support/ leaves a consistent module graph (removed llarhub/libcxx and llarhub/llvm-c are no longer referenced by any Go import there). Generated fixtures are mechanical and out of scope.
Findings below are non-blocking; the main one worth a decision is whether enum/union forward declarations should get the same treatment.
| switch decl.Kind { | ||
| case lc.Cursor_ClassDecl, lc.Cursor_StructDecl: |
There was a problem hiding this comment.
[P2] Same forward-decl misattribution likely applies to enum/union
This switch only special-cases Cursor_ClassDecl/Cursor_StructDecl. Enum and union declarations short-circuit on the exact same condition elsewhere (enum.go:65 and union.go:67 both do if decl.IsCursorDefinition() == 0 { return }), so an enum/union forward-declared in file A and defined in file B can be attributed to the wrong file by the same mechanism this PR fixes for class/struct. Enum forward declarations with a fixed underlying type (enum E : int;) are legal and common C++11.
If the broader fix is intended, consider also handling lc.Cursor_EnumDecl (and lc.Cursor_UnionDecl). If class/struct is the deliberate scope, a short comment explaining why would prevent a future reader from assuming it was an oversight. (Typedefs are correctly excluded — they are not a forward/definition pair.)
|
@copilot Fix above review comments. And revert any changes in |
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
Co-authored-by: xushiwei <396972+xushiwei@users.noreply.github.com>
Restored the LLVM fixture dependency metadata; the affected |
TestPythonpassed despite placingX_PyTssTinpythread.goinstead ofcpython-pythread.go.X_PyTssTintocpython-pythread.go; keep itsPyTssTalias inpythread.go.