Files
tilelang/testing/python/debug
cc106fa2ad [Feature] Add lower-trace support for debugging & rebased (#2725)
* [feat] add lower-trace support for debugging

* [fix] address review: rebase, doc migration, lower_trace robustness

Address CodeRabbit + SiriusNEO review feedback on #2470:

Blocking (SiriusNEO):
- Rebase onto tile-ai/main (resolve docs/ + tilelang/__init__.py conflicts).
- Move IR Lower Trace doc from docs/tutorials/ to docs/tools/lower_trace.md
  (alongside pass_diff.md); add index entry and 'superseded' pointer on
  pass_diff.md; cross-link from the tutorial.

CodeRabbit Major:
- lower_trace/__init__.py: finally block uses active_exc pattern so a
  generate_html() failure can no longer mask the real lowering exception.
- lower_trace/html.py: sanitize rec.phase into DOM-safe IDs via _safe_id()
  before embedding in id="..." / selectors (avoids markup/JS breakage and
  local HTML injection from special characters).

CodeRabbit Minor:
- test_lower_trace.py: restore caller's TL_LOWER_TRACE* env after the guarded
  tilelang import instead of permanently clearing it.
- lower_trace/__init__.py: terminal mode prints a FAILED stanza (pass name,
  exception, pre-pass IR) before re-raising so the failing step is visible.
- lower_trace/core.py: _get_codegen_output_path() no longer auto-writes
  codegen.cpp in terminal-only mode (explicit override still honored).
- lower_trace/html.py: expandAll()/collapseCtx() null-guard the table lookup
  so a changed diff with no table fails safe.

Cleanup:
- Add docstrings to test helpers and tools.__getattr__ (coverage now 94%+).
- ruff check + format clean.

* [Docs] Add lower trace to tools sidebar

* [fix] route lower-trace env vars through tilelang.env

Register TL_LOWER_TRACE / TL_LOWER_TRACE_DIR as EnvVar in the central
Environment class with get_lower_trace_mode()/get_lower_trace_dir()
parsers, mirroring the existing TILELANG_PASS_DIFF convention, instead
of reading os.environ directly in the lower_trace module.

* [fix] simplify lower_trace lazy-import in tools __getattr__

Drop the redundant globals() cache assignment (import_module already
binds the submodule onto the parent package) and fix the docstring: the
module is imported lazily for cost, not to defer monkey-patch side
effects, which happen in enable(). Note why importlib is required over
"from . import" (the latter re-enters __getattr__ and recurses).

---------

Co-authored-by: caojian5 <caojian5@huawei.com>
Co-authored-by: SiriusNEO <chaofan@deepseek.com>
2026-07-22 16:27:01 +08:00
..