Implementer's Guide (HOWTO)
This page is the unified entry point for every change; it is not the source of the rules. The sole authoritative source for the rules is:
- Changing code → coding-rules.md (three prohibitions + D0–D4, the precise rule source) and RFC-039 and the supplementary
architecture/documents- Changing documentation → docs-rules.md (Diátaxis classification rules + wiki-style language style)
This page does only two things: perform a mandatory self-check before starting work and determine whether a change is a "patch-style fix." If this page conflicts with the authoritative rule source, the rule source takes precedence.
Step 0: Determine What You Are Changing
| Your change | Which section to read | Authoritative rule source | Pre-submission validation |
|---|---|---|---|
Changing code (src/, tests/) | Section 1 | coding-rules.md | See the end of Section 1 |
Changing documentation (docs/) | Section 2 | docs-rules.md | See the end of Section 2 |
| Changing both | Read both sections | Follow both rule sources | Run both sets of commands |
Note: Changing code often requires documentation to be updated in parallel—error-code tables, CLI options, and user-visible behavior are all asserted in the documentation. Passing Section 1's acceptance criteria does not mean you are done. First answer: "Where is this behavior described, and does it need to change alongside this modification?"
1. Changing Code
Which Layer Your Change Belongs To
First read the four-layer model and each layer's contracts in RFC-039 to determine which layer the change belongs to. Then use 03 to determine which C1–C6 tier it falls under. For a cross-layer change or one that alters an external contract, first establish the basis in a resolution; if you cannot state the basis, stop and fill it in.
Pre-Work Self-Check (Complete Every Item Before Writing Code)
- [ ] I have read the architecture document and the full text of the RFC resolution corresponding to this change, rather than only the task title
- [ ] I have read the actual context of the code being changed by opening the file, rather than imagining it from the task description
- [ ] I know the acceptance-criterion level for this task (C1 zero-diff / C2 diagnostic suite / C3 diagnostic codes / C4 behavioral equivalence / C5 AST + diagnostics + behavior / C6 pure deletion)
- [ ] I have classified the error type (A–F, according to the triage criteria in 03-ir-and-criteria): A/B/C (the old behavior was not successful—crash/stack overflow, silent failure, silent mismatch, or silently giving the wrong answer) may be fixed alongside the refactoring, but it must go red first, then green, and must not change the externally visible behavior of programs that previously succeeded; D/E/F (user-visible semantics / external contract table / RFC-level design) must first be adjudicated by the user (see the criteria in 03 § Semantic-Correction Triage)
- [ ] I have run D0: Does this change touch any table (error codes/opcodes/types/stages)? Which module is the authoritative source? If you cannot name the module, you have not investigated
- [ ] I have run D1/D2: Can newly added type/enum/constant tables be expressed using existing concepts plus parameters? Do they have the same semantics as existing concepts? (For identical semantics, using import aliases to bridge the gap is forbidden)
- [ ] I have run D4: Does the new code belong to an existing category of responsibility in the target module? (See the directory responsibility table in 01-architecture.md for the authoritative definitions)
- [ ] I have run the trade-off criterion: Is my (or the proposal sponsor's) reason for rejecting an option based solely on correctness and readability? Rejecting a proposal because it has "a large change surface," "requires a new mechanism," or "is expensive" is an invalid rejection, and the review will be sent back (Part 2 of coding-rules); for trade-offs requiring a user decision, provide all four items specified by the repository-root
AGENTS.md - [ ] Is my new mechanism of the "register-and-consume" type (one party registers data and another consumes it)? If so, were the directly driven end-to-end tests for the producer and consumer delivered in the same batch? A consumer test that manually constructs registered data is a hidden channel, and the review will be sent back (Part 6 of coding-rules; see 01-architecture for the precedent of LSP capability routing)
- [ ] If this task requires writing or changing tests: I have read test-specification.md—the
test_<what>_<scenario>naming prefix, three-part AAA comments for tests longer than five lines, custom assertion messages, enum matching withassert!(matches!(...)), nouse super::*, and no inlinemod tests {} - [ ] If my change affects IR or corpus execution behavior (frontend/ir_gen/std/corpus
.yx): I plan to update the IR snapshots and corpus differential baselines in the same commit (see the common-commands section of AGENTS.md for the commands), and manually review both diffs—parallel workstream #385 once failed to synchronize the snapshot and was blocked by the gate (precedent: dabdfd96) - [ ] If the change follows the A/B/C triage criteria in 03-ir-and-criteria, I have confirmed that the red criterion already exists and is currently red
- [ ] I have not prepared to "delete failing tests" or "relax the criteria" merely to pass acceptance—if that is impossible, the implementation is defective; report it truthfully rather than relaxing the criteria (C5′ does not exist)
- [ ] I have asked myself where this behavior is described and whether this change requires a documentation update (change → Section 2)
Is This a "Patch-Style Fix" (D3, Stop When One Applies)?
1) 同一行为需要在 ≥2 处复制? → 是 → ⛔ 必须提到共享层,禁止复制
2) 需要新增"第 6 个入口/接线点"? → 是 → ⛔ 禁止手工接线,改为登记进阶段表
3) 一次修改要同步改 ≥3 处同义映射? → 是 → ⛔ 这是架构变更,停工,走设计文档流程
4) 以上皆否 → 允许局部补丁,但必须附带回归测试The third rule is the reason this guide exists. Changing ≥3 synonymous mappings means maintaining a parallel source of truth—the correct move is to eliminate the parallel source, not add another one.
A Few Easy-to-Miss Hard Rules
- Do not change code you have not read: you may not modify anything whose file you have not opened or whose references you have not grepped. Line numbers are based on the current repository state because line numbers in documentation drift.
- Leave no deferred implementations: core functionality must not contain
todo!()/Vec::new() // Not implemented yet/ "fix it later in a separate issue." If you find one, fix it; do not introduce new deferrals. The two real losses in.42—upvalue_countandglobals—must be persisted;exception_handlersis a dead field and must not be persisted. - Verification items must be verified line by line: when a task is marked "must be verified line by line; equivalence must not be assumed," write your verification conclusion in the PR description.
- Deleting tests to get a green build is a violation: the number of tests after submission must not be lower than before submission.
- Do not manually check mechanical issues already covered by tooling: fmt / clippy /
build.rsgates /scripts/ci/check-*.py. Reviews should focus only on what machines cannot check (responsibility classification, D3).
What to Do When You Are Stuck
| Situation | Correct action | Wrong action |
|---|---|---|
| The criterion does not pass | Report truthfully and fix the implementation; if the criterion appears to be wrong, return to 03 and propose changing it | Add a whitelist or exemption to the criterion |
| You discover that a design premise does not hold | Return to RFC-039 or 03, change the criterion, and explain why | Bypass the decision and proceed quietly |
| The task is larger than expected | Split it into independently verifiable small steps, with only one criterion per step | Use one enormous commit that mixes multiple acceptance criteria |
| You find a contradiction between documentation and code | Trust the code first, then fix the documentation (precedent: the layer-order table in layers/README.md does not match the actual call order) | Write code according to incorrect documentation |
Pre-Submission Validation (Code Changes)
cargo fmt # Formatting (required)
cargo clippy --all --all-features --all-targets -- -D warnings
python scripts/dev/testsuite.py run fast # Required before submission: lib + integration targets; see below
python scripts/ci/check-test-channel.py # One source of truth across four locations (this page / AGENTS.md / test-specification / pre-commit)
python scripts/dev/test-gate-census.py --check # The census table matches the current tree (pre-commit runs this automatically when .rs files / the census table change)The target set for run fast is explicit: --lib (unit tests under src/) plus four integration targets: integration / formatter_integration / yx_runner / yx_multifile_runner. The first stage of pre-commit runs this command, and its second stage runs cargo test --all --quiet to block the commit. Doctests (cargo test --doc) and corpus differentials are not covered by run fast; CI provides the backstop. Exclusive test waves that do not fit within the budget will be listed individually at the end as "Skipped N tests," with a fallback path; they are never silently skipped.
Before pushing, also run the CI-only gates. Because they are not included in the local checklist, they effectively do not exist until you run them:
python scripts/ci/check-docs-truth.py
python scripts/ci/check-boundary.py --strict
python scripts/ci/check-fanout.py --strict
python scripts/ci/check-docs-refs.pyThe error-code reference page is a build-time artifact and is not checked in: when the documentation site is built, scripts/docs/gen-error-code-docs.py regenerates it from the code registry and locales/*.json for both zh and en, so it is no longer regenerated and checked in locally. When changing diagnostic codes, change the authoritative sources—the define_codes! registry and its copy: every new code must have entries in both locales/zh.json and locales/en.json, or the generated page will show "no locales entry" for that code. To preview the generated result, run node docs/gen-error-docs.js.
2. Changing Documentation
Classification: Which Directory Does This Document Belong To?
Use the decision tree in docs-rules.md §1 to answer; the answer must be unique (tutorial / guide / reference / explanation / dev / rfc). If you cannot arrive at a unique answer, this document is serving two audiences—split it before making any changes.
Pre-Work Self-Check (Complete Every Item Before Changing Documentation)
- [ ] I used the docs-rules §1 decision tree to determine the directory, and the answer is unique
- [ ] I grepped for similar content; no content has ≥2 copies (if it does, merge the copies rather than adding a third)
- [ ] I checked
docs/glossary.jsonand existing documentation, reused existing terminology, and did not invent new names - [ ] New documentation: the frontmatter
titlehas been written, and the page has been added to the sidebar (config.js+i18n/en.json;generateSidebarscans the directory, so no manual link is needed) - [ ] Moving or renaming documentation: all six synchronizations have been completed (see "Six Synchronizations When Moving a Document" below)
- [ ] The language style passes docs-rules §2: active voice, definitive statements, present tense, consistent terminology, and no marketing language
Six Synchronizations When Moving a Document (Moving = Changing the URL; None May Be Omitted)
- Move it with
git mv(preserving the file history) - Site-wide links: grep for the old path and update every occurrence (the build's dead-link check provides a backstop, but it does not do this for you)
- Sidebar and navigation:
docs/src/.vitepress/config.jsanddocs/src/.vitepress/i18n/en.json - The
en/mirror: move the corresponding English file in sync - Scripts and configurations that reference the path:
scripts/,docs/scripts/,.github/workflows,AGENTS.md, andREADME.md - The cache key in
docs/src/.i18n-cache.json(the key contains the file path)
Is This a "Patch-Style Fix" (Documentation Version of D3, Stop When One Applies)?
1) 同一内容要改到第 2 处副本? → 是 → ⛔ 合并副本,只留一处
2) 要给一个目录新增第 N 个"例外说明"? → 是 → ⛔ 这是分类问题,先调结构
3) 读者要在两个顶级目录间来回跳转才能凑齐一件事? → 是 → ⛔ 拆分或合并,先调结构
4) 以上皆否 → 允许局部修改Pre-Submission Validation (Documentation Changes)
cd docs
pnpm docs:build # Dead links are not tolerated; the build must pass
pnpm lint:md # markdownlint
pnpm format:md:check # prettier
python ../scripts/ci/check-docs-examples.py # Documentation examples execute successfully
python ../scripts/ci/check-docs-orphan.py # Orphan pages and duplicate H1 headings
python ../scripts/ci/check-docs-truth.py # Version injection and factual reconciliation
python ../scripts/ci/check-docs-refs.py # Reference paths resolve (only paths in the repository count)markdownlint cannot catch VitePress Vue compilation errors (angle-bracket placeholders are treated as elements and produce Element is missing end tag), and in a documentation-only commit it is skipped with "no files to check"—a real build is the only criterion. Always put placeholders in backticks.
If you changed anything under rfc/, also run:
python ../scripts/rfc/check_tracking.py # RFC status consistency3. Validation Measurements (Batch Trees)
Measurements must be performed on a frozen revision. Cargo fingerprints include source paths—switching trees = a full rebuild; switching revisions within the same tree = an incremental build. Therefore, use one tree per batch, fixed inside the repository at target/yx-scratch/<batch>/tree (already covered by .gitignore). Do not run git worktree add or git clone directly, and do not create a directory outside the repository.
Workflow: init <batch> creates the tree (the initial full build takes about 5 minutes / about 3 GB) → use <batch> --rev <sha> --by <member> --task <id> locks the tree and switches the revision → build <batch> performs the unified build (always use cargo build --bin yaoxiang-rs; do not invent your own command) → measure → release <batch> unlocks it → close out with gc and paste the status output into the task output. See python scripts/dev/scratch.py --help for the parameters.
- Only one holder is allowed at a time; implementers do not enter this tree (they write code in the main repository working tree).
- Only when two people genuinely need to measure different revisions in parallel should you open a second
<batch>-btree and record the reason in the batch record (the cost = another full build). - Command forms for
trial:trial <batch> --patch <p> -- <command...>(recommended; tokens after--are passed through as the command unchanged, and the command may contain-/--arguments) andtrial <batch> <command...> --patch <p>(usable when the command does not begin with-) are equivalent.--patchmust appear before--; the command must not be empty; mixing the two forms (commands on both sides of--) is rejected (exit 2). - After
trial, you must runbuildbefore measuring: trial's mechanical restoration covers only source files, and the mutation test has already rebuilt the binary in the batch tree—without another build, all subsequent measurements will come from the mutated artifact. - Probes (
.yx) also belong intarget/yx-scratch/<batch>/(target/is ignored and is not included in corpus differentials); they are workspace artifacts, not documentation sources (see AGENTS meta-rule ①).
References
- coding-rules.md — three prohibitions, D0–D4, red lines, and the review checklist (the authoritative code rules)
- docs-rules.md — Diátaxis classification rules and wiki-style language style (the authoritative documentation rules)
- 03-ir-and-criteria.md — definitions of the C1–C6 criteria
- 01-architecture.md — authoritative definitions of responsibility categories and the target directory structure
- RFC-039 — four-layer model, phase contracts, and criterion grading
