name: header-cycle-breaker description: Guide for breaking cyclic dependencies in V8 headers and resolving cascade IWYU failures.
Header Cycle Breaker Skill
This skill outlines the systematic approach to breaking cyclic dependencies in
V8 headers, specifically focusing on moving heavy inline includes to more
localized .cc files or non-inline headers, and resolving the resulting cascade
of "undefined inline function" errors (IWYU - Include What You Use style).
When to Use
Use this skill when:
- You are tasked with breaking a header cycle in V8 (e.g., core-to-wasm cycle).
- You need to remove an
-inl.hinclude from another-inl.hor.hfile. - You encounter a flood of
[-Werror,-Wundefined-inline]errors after modifying a heavy header.
Workflow
Phase 1: Identification and Cycle Breaking
- Identify the cycle: Use tools or subagents to map the include graph and find the cyclic path.
- Plan the break: Identify a point where an
-inl.hcan be replaced with its non-inline counterpart (.h) or where an include can be moved entirely to implementation files. - Apply the break: Modify the header file to break the cycle.
Phase 2: Resolving the Cascade (IWYU)
Breaking a heavy include chain will cause many implementation files (.cc) and
even generated files to fail because they were relying on transitive includes
for inline definitions.
- Do not panic: Expect tens or hundreds of compilation errors initially.
- Aggressive Delegation: Spawn subagents for independent file failures. Prompt them to identify missing headers for specific undefined symbols.
- IWYU Application: For each failing file:
- Identify which inline method is undefined.
- Find which
-inl.hfile defines it. - Include that
-inl.hfile directly in the failing.ccfile, preferably within appropriate guards (e.g.,#if V8_ENABLE_WEBASSEMBLY).
- Repeat until clean: Build, fix, and build again. This is an iterative process.
Phase 3: Special Case - Generated Files
If a generated file (e.g., objects-printer.cc) fails with undefined inline
methods:
- Trace to generator: Realize that editing the generated file is temporary.
Find the source generator (e.g., in
src/torque/). - Modify the generator: Update the generator code to emit the necessary
#includestatements in the files it generates. - Rebuild the generator: Recompile the tool (e.g., Torque) and let the build system regenerate the files.
Best Practices
- Keep files isolated: Do not revert the cycle-breaking change when you see cascade errors. Push through by fixing the files.
- Use guards: Always wrap Wasm-specific includes in
#if V8_ENABLE_WEBASSEMBLY. - Check trait caching: Be aware of C++ trait caching issues if you encounter weird subtyping errors during header reorganization.