Skip to content

Move call target normalization into C tracer#413

Merged
pschanely merged 1 commit into
pschanely:mainfrom
nyashahama:ch-normalize-call-target-c
May 21, 2026
Merged

Move call target normalization into C tracer#413
pschanely merged 1 commit into
pschanely:mainfrom
nyashahama:ch-normalize-call-target-c

Conversation

@nyashahama
Copy link
Copy Markdown
Contributor

@nyashahama nyashahama commented May 20, 2026

Addresses part of #115.

This moves the call target normalization currently done inside TracingModule.trace_op() into the existing _crosshair_tracers C extension. The stack decoding remains in call_stack_info() from #410, while keyword normalization and replacement write-back stay in Python, so this keeps the behavior boundary small.

What changed:

  • Added _crosshair_tracers.normalize_call_target() for the __self__ / __call__ / __func__ / type-level descriptor normalization path.
  • Updated TracingModule.trace_op() to call the C helper before handling keyword dictionaries and trace_call().
  • Added direct tests for bound Python methods, callable instances, C-level bound methods, reference stability, and non-AttributeError propagation during type-level lookup.
  • Added an integration test showing callable instance calls still get patched through the tracer.

This includes the error handling requested on #411: type-level lookup clears AttributeError, but propagates other descriptor/access errors instead of continuing with an exception set.

This intentionally does not touch the open CompositeTracer removal work in #409 or the opcode callback argument caching work in #412.

Verification:

  • python3 -m venv .venv && .venv/bin/python -m pip install --upgrade pip setuptools wheel && .venv/bin/python -m pip install --editable '.[dev]'
  • .venv/bin/python setup.py build_ext --inplace
  • PYTHONHASHSEED=0 .venv/bin/python -m pytest crosshair/tracers_test.py::test_normalize_call_target_helper_is_exported -q failed before implementation as expected.
  • PYTHONHASHSEED=0 .venv/bin/python -m pytest crosshair/tracers_test.py crosshair/_tracers_test.py -q -> 18 passed
  • PYTHONHASHSEED=0 .venv/bin/python -m pytest crosshair/core_test.py crosshair/libimpl/builtinslib_test.py crosshair/tracers_test.py crosshair/_tracers_test.py -q -> 564 passed, 2 skipped
  • CROSSHAIR_EXTRA_ASSERTS=1 PYTHONHASHSEED=0 .venv/bin/python -m pytest crosshair/core_test.py crosshair/libimpl/builtinslib_test.py crosshair/tracers_test.py crosshair/_tracers_test.py -q -> 564 passed, 2 skipped
  • CROSSHAIR_EXTRA_ASSERTS=1 PYTHONHASHSEED=0 .venv/bin/python -m pytest -m smoke -n auto --dist worksteal crosshair -q -> 13 passed
  • .venv/bin/python -m black --check crosshair/tracers.py crosshair/tracers_test.py
  • .venv/bin/python -m isort --check-only crosshair/tracers.py crosshair/tracers_test.py
  • .venv/bin/pre-commit run flake8 --files crosshair/tracers.py crosshair/tracers_test.py
  • git diff --check

I also attempted the full local xdist suite. It reported 8 failures in symbolic/time-sensitive areas under local parallel load; each failed nodeid that I reran in isolation passed with PYTHONHASHSEED=0. I left this note here so CI remains the source of truth for the full matrix.

@pschanely pschanely merged commit 2891ce3 into pschanely:main May 21, 2026
22 of 37 checks passed
@pschanely
Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants