Skip to content

RFC-029f: Compilation Target Roles and Import Surface Semantics ​

Abstract ​

Implementation correction (2026-10-08, RFC-029g): The pub keyword was removed in its entirety by RFC-029g. In the body of this document, all references to "pub exemption / pub files / unused pub warnings" should be read as "top-level bindings + intra-package reference pool": role classification (Script / Bin / Lib / Internal / Test) and import surface semantics remain unchanged; only the criterion for dead-code exemptions changes (see 029g and the criteria in docs/src/reference/warning-code/warning-codes.md).

This RFC fills the extension slot under RFC-029's "Sub-RFC Planning" (029b–029e are already occupied, so 029f comes next): it defines a compilation target role model for source files (Script / Bin / Lib / Test / Internal) and its import surface semantics—without a manifest, roles are inferred from entry-point reachability (zero configuration); with a manifest, they are declared explicitly through [lib] / [[bin]] / [exports] (fields already defined by RFC-015). It fills four semantic gaps: how the cross-package import surface is computed, the scope in which the pub exemption for dead-code warnings applies (Decision B in #321), the relationship between [exports] and Registry reachability, and terminology disambiguation between RFC-014b [binaries] (precompiled distribution artifacts) and source files in the bin role.

Motivation ​

Upstream and Boundary Rationale ​

RFC-029's (Accepted) entry-point selection and visibility decisions are the direct upstream of this RFC:

Entry-file selection priority: 1. [run].main 2. The path of the first [[bin]] 3. src/main.yx (conventional default). — RFC-029 §Inter-Package Cycles: Revisited

Visibility: None. Scope + distribution boundaries cover all scenarios and do not require new keywords. — RFC-029 §Design Decision Record (2026-07-30)

The second decision is this RFC's design red line: import surface semantics must not introduce any new visibility keyword. It must be carried solely by "distribution boundaries" (file roles + declared export surfaces).

Four consumers have each encountered the same wall:

ConsumerPoint of blockage
#321 dead-code warningsDecision B, "pub = public interface, never report," exists because there was no role model to distinguish genuinely public interfaces from merely public-looking ones; whether an unused pub in a bin should be reported (Option A) has remained undecided
RFC-014c workspaces (under review, #113)When member packages use one another, how the import surface is computed—[exports], a single [lib] file, or all pub files—has no semantic provision anywhere
RFC-015 configuration system (Accepted)The [lib] / [[bin]] / [exports] fields are already defined; except for RFC-029 consuming the entry-point priority, the semantics of the remaining fields (especially the relationship between [exports] and Registry reachability) have not been aligned
RFC-037 packaging / RFC-029c caching (draft, #293)Both package artifact selection and the cache-unit boundary for incremental recompilation require the role model as a prerequisite

Current Problems ​

Four semantic gaps (inventory as of 2026-09-12, after reviewing the full text of 014/014a/014b/014c/015/029):

  1. The cross-package import surface is undefined. The cross-reference example in 014c only shows a directory structure (src/lib.yx); there is no provision stating what use utils.helper can access. The current implicit rule is "all top-level pub files in the package"—internal implementation files are also pulled into the namespace, making dependency boundaries effectively meaningless.
  2. The dead-code pub exemption has no defined scope. Decision B in #321, "pub is never reported," is too conservative in a single-file script (a script has no external consumers, so pub is meaningless), but too permissive in the entry file of a multi-file project (a pub in the root file that no one imports is dead code). Without a role model, the dividing line between Options A and B cannot be drawn.
  3. The three export concepts are not aligned. [exports] (015, path mapping), [lib] (015, single-file path), and Registry reachability (029, reachable from the entry point along use edges)—there is no provision stating whether these are inclusion relationships, equality relationships, or independent mechanisms.
  4. Terminology collides. RFC-014b's [binaries] refers to precompiled distribution artifacts (the .so/exe download-priority mechanism), which is an entirely different layer from a "bin target" (a source-code role). Once 014c is implemented, the two will inevitably appear together; failing to disambiguate them now will cause continuing confusion.

Empirical evidence: the conservatism of Decision B is already an actual pain point. The #321 M2 retrospective records that the structural reason the entire W1001–W1005 family was silent under the default configuration was precisely "all pub declarations were treated as public interfaces." This is compensatory behavior caused by the missing model, not the final state.

Proposal ​

Core Design: File Role Model ​

Roles are file-level attributes (consistent with 015's field granularity: [lib] is a single file, [[bin]] is a file list, and [exports] is a file mapping), not package-level switches.

RoleClassificationSemantics
BinThe file targeted by [run].main / [[bin]].path; or, when there is no manifest, a file containing main that is not used by any fileProgram entry point. Requires a binding named main, which may be either a value or a function: a function main is called with zero arguments at entry, while a value main is evaluated during initialization (its evaluation result is not called again even if it is a function value). A missing main is a compile error (E3020); the top level must not contain executable statements. Its pub declarations may be reported as dead code (there are no out-of-package consumers); main is a reachability root
LibA file matched by an [exports] mapping; or [lib].path; or, when there is no manifest, a file referenced by another file's useDistribution boundary. Its pub declarations are exempt from dead-code reporting (out-of-package consumers cannot see them; prefer under-reporting); symbols exported through it are visible across packages
TestA file matched by the RFC-036 test-file rules (existing conventions such as the tests/ directory and *_test.yx); no explicit [[test]] declaration is introducedTest code. It does not participate in dead-code determination; its references count toward the reachability roots of the code under test
InternalWhen the package has a manifest, a file that is neither on the export surface nor contains mainIntra-package implementation. pub declarations are exempt until Phase 2 (reachability is then tightened using the intra-package use graph, with validation against a Bin-role corpus as a prerequisite); out-of-package use is unreachable
ScriptA file executed directly by itself (run foo.yx)No entry-point concept. Top-level statements, including binding initialization, constitute the program body in source order; main is an ordinary binding and is not called automatically—write main() if you want to run it. The Registry contains only std

Classification priority: explicit manifest declaration > entry-point reachability inference > the 036 test convention. An explicit declaration always wins—inference is only the default when no declaration exists.

Entry-Point Determination ​

The role model is not only used for dead-code analysis; it also drives entry-point determination. The entry-point rules for each role are:

RoleEntry-point rule
Script (no manifest)No entry-point concept. Top-level statements, including binding initialization, constitute the program body in source order; main is an ordinary binding and is not called automatically—write main() if you want to run it
Bin (with manifest)Requires a binding named main (either a value or a function: a value main is evaluated during initialization, while a function main is called with zero arguments at entry); a missing main is a compile error (E3020). The top level must not contain executable statements
Lib / Internal / TestDoes not require main (they are not entry points)

The entry points of Script and Bin must be mutually exclusive: "under Script, main is not special" and "under Bin, main is the entry point" cannot both hold—if a Script both executes top-level statements and implicitly calls main, a script that explicitly writes main() would run twice (#356). A Script therefore has exactly one execution entry point: its top-level statements.

Difference between role classification and entry-point determination (implementation note): entry-point determination uses the "presence or absence of a manifest" (find_project_root().is_some()), not roles::classify(). The reason is that classify answers "who consumes this file" (serving dead-code analysis); a file with a manifest but no main is Internal in classify (because no other file uses it, reasonably), but if the user runs it as the entry point, it must have an entry point. These are two different questions and therefore use different criteria.

Execution form of a value main (Decision #388): functions are already values (unified at the type layer), and the entry point is determined by binding existence, not callability—a value main and a function main differ only in evaluation strategy. A value main has no implicit entry-point call (#356 prevents double execution: initialization and entry-point invocation are never combined), and has the same execution form as Script. Its evaluation is part of the initialization sequence: bindings execute in global topological order, while independent bindings execute in source order. Therefore, moving a Script's top-level statements into main = { ... } and then moving that into a Bin is not an order-preserving migration—scattered statements execute in source order, whereas binding initialization executes in topological order; initialization that must occur first should be made an explicit dependency of main. A non-callable value main such as main: Int = 5 is legal but produces a program with no observable effect (analogous to an empty Rust fn main() {}).

See §3.11 of docs/src/reference/language-spec/syntax.md.

Examples ​

toml
# yaoxiang.toml (all fields are already defined by RFC-015; this RFC adds no configuration surface)
[lib]
path = "src/lib.yx"

[[bin]]
name = "my-cli"
path = "src/cli.yx"

[exports]
"." = "src/lib.yx"
"./internal-helper" = "src/helper.yx"   # ← This, not pub, determines cross-package visibility
yaoxiang
# src/cli.yx (Bin role)
pub unused_fn = (x: Int) => x    # ← W1001 may be reported: a bin has no out-of-package consumers
main: () -> Void = { ... }

# src/lib.yx (Lib role, on the export surface)
pub api_fn = ...                 # ← Never reported: out-of-package consumers cannot see it

# src/other.yx (Internal role, not on the export surface)
pub semi_api = ...               # ← Exempt until Phase 2 (prefer under-reporting); tighten later using the use graph

Import Surface Semantics ​

The resolution order for a cross-package use pkg.x is as follows (the first match takes effect):

  1. If an [exports] mapping exists → the import surface is the set of files listed by the mapping, and x must be a top-level binding in those files;
  2. Otherwise, if [lib].path exists → the import surface is that single file;
  3. If neither exists (manifest dependencies, path dependencies on bare directories) → preserve current behavior: all top-level files are importable (for compatibility with existing behavior; further tightening is left for separate consideration).

Workspace members: an export surface is defined only by the member package's own manifest; the workspace root must not override or extend a member's export surface—member self-containment is a core 014c design principle, and root-level overrides would break encapsulation.

Relationship to Registry reachability (aligned with 029): [exports] / [lib] define the legal starting-point set for cross-package resolution; once the starting points have been determined, the Registry still expands them according to 029's "reachable from the entry point along use edges"—internal files imported by an exported file enter during linking, but do not create new cross-package starting points.

Boundaries with Existing Plans ​

NeighborBoundary
RFC-029d "CLI --entry entry-point override" (planned)029f defines the role model; 029d consumes it—--entry is the CLI-level override mechanism for the Bin role
RFC-014b [binaries]Terminology disambiguation: [binaries] refers to precompiled distribution artifacts (the download-priority mechanism), whereas [[bin]] declares source-code roles. The former exists in a dependency package's manifest, while the latter exists in the current package's manifest; they are not interchangeable
RFC-014c workspacesThe import surface for cross-references between member packages is the resolution order defined by this RFC; workspace coordination mechanisms (members, shared lockfile) remain the responsibility of 014c
RFC-036 testsTest-role classification directly adopts 036's existing file rules and introduces no new convention
#321 dead codeDecision B (pub is always exempt) is explicitly downgraded to "transitional semantics when no target exists"; reporting pub for the Bin role is this RFC's implementation of Option A

Detailed Design ​

Role Classification Algorithm (Within the Orchestrator) ​

fn classify(files, manifest, entry_reach) -> Map<File, Role>:
    # 1. Explicit layer: manifest declarations take priority
    for f in manifest.exports.values():  role[f] = Lib
    if manifest.lib_path:                role[lib_path] = Lib
    for b in manifest.binaries:          role[b.path] = Bin
    if manifest.run_main:                role[run_main] = Bin

    # 2. Inference layer: infer by entry reachability where no declaration exists
    for f in files where role[f] 未定:
        if f 被 ≥1 个非自身文件 use:      role[f] = Lib
        elif f 含 main 且无其他文件 use 它: role[f] = Bin
        else:                             role[f] = Internal

    # 3. Test layer: a 036 rule match → Test (overrides Lib/Internal, but not an explicit Bin)
    apply_rfc036_test_rules(files, &role)

    # Single-file direct execution: bypass the entire model; behavior remains unchanged
    if no manifest and single_file:      all Script

Compiler Changes ​

  • frontend/config.rs: manifest parsing gains the mapping from [exports] to the role table (field parsing already exists in 015).
  • frontend/module/orchestrator.rs: insert a role-classification stage before Registry construction; cross-package resolution validates use targets according to the import-surface order, and out-of-bounds targets report the existing module_not_found family (no new error code; the message gains a "not in the export surface" notice).
  • typecheck/dead_code.rs: the entry-point set changes from "main + all pub" to "main + pub in Lib-role files" (Bin may be reported immediately; Internal remains exempt until Phase 2, as described in the implementation strategy).
  • LSP (RFC-017): completion/hover "importable items" are filtered by the import surface; the missing-main diagnostic is reported only for Bin-role files.

Runtime Behavior ​

No change. The role model is purely a compile-time/parse-time semantic and does not affect the IR or execution.

Backward Compatibility ​

  • Projects without a manifest: behavior remains completely unchanged (the inference layer restores current behavior—a file that is used is Lib, and a file containing main is Bin). The only incremental dead-code warning occurs in Bin files: an unused pub in a root file that no one imports changes from silent to W1001—this is the expected behavior under #321 Option A and is not a breaking change.
  • Projects with a manifest: when [exports] is declared, the import surface narrows from "all pub files" to the declared surface. This is the only point where behavior is narrowed: code that depends on another package's internal files will begin to report module_not_found. Given that the package ecosystem has not yet been established (029: "there is currently no third-party package ecosystem"), the impact is zero; nevertheless, a transition period spanning one minor version will be provided (out-of-bounds targets warn before becoming errors).

Trade-offs ​

Advantages ​

  • No new configuration surface: every field is already defined by 015; this RFC only adds semantics.
  • No new keywords: the import surface is carried by distribution boundaries, mirroring 029's "visibility does not exist" decision.
  • One model serves all four consumers (#321 / 014c / 029a / 037), so they no longer encounter the same wall separately.
  • Zero cost on the no-manifest path: the scripting language's zero-configuration nature is fully preserved.

Disadvantages ​

  • Role inference ("used implies Lib") misclassifies a utility file as Lib in the common shape where an entry file uses a utility file, making its pub exemption broader than the ideal granularity. This is an intentional choice in the under-reporting direction; tightening requires call-direction analysis on the use graph and will not be included in the first version.
  • Narrowing the import surface through [exports] is a breaking semantic tightening (although a transition period is provided).

Alternatives ​

AlternativeDescriptionReason not adopted
Top-level RFC-040Allocate a new top-level numberModule-graph semantics (import surface/reachability/entry points) all belong to 029's territory; splitting them into a top-level RFC would create two top-level documents for the same object, and the 029b–029e slot pattern is already established
Incorporate into 014cAdd as a section of the workspace RFCThe dependency direction would be reversed: the language layer (029x) defines semantics, while the package layer (014x) consumes them. 014c is still under review, and expanding its scope midway would impede its implementation
Option A unchanged (#321 menu)Require manifest [[bin]]/[[lib]] targets before dead-code semantics applyThis would introduce mandatory configuration for a narrow slice (an unused pub in a root file containing main); this RFC's inference layer provides the same benefit with zero configuration
Pure entry-point inference (no manifest layer)Do not consume 015 fields[exports] is already an accepted 015 field and cannot be bypassed for cross-package import surfaces; leaving it undefined would leave a gap for 014c

Implementation Strategy ​

Phased Delivery ​

  • Phase 1: role classification + import-surface resolution + reporting Bin pub (Internal/Test remain exempt)
  • Phase 2: tighten Internal pub to "report when unreachable in the intra-package use graph"—the prerequisite is that, after Phase 1 is implemented, validation of the Bin-role warning corpus confirms no false-positive regression; implementation is triggered when ready, with no timetable

Dependencies ​

  • Prerequisites: RFC-029 orchestrator (implemented), RFC-015 manifest fields (defined).
  • Depended upon by: #321 (reporting Bin pub), RFC-014c (import surface), RFC-029a (roles as cache-unit boundaries), RFC-037 (artifact selection), RFC-029d (--entry override).
  • Implementation order relative to RFC-014c: before 014c passes review, 029f's import-surface order should be finalized, and 014c should consume it by reference to avoid expanding scope midway through review.

Risks ​

  • Deviation between role inference and user intuition (the first trade-off above) → present all incremental behavior as warnings (non-blocking), so it can be disabled at any time.
  • Managing the transition period for the [exports] narrowing → warn before reporting an error in the next minor version.

Open Questions ​

All three draft-stage questions have been decided as of 2026-09-13 (the decisions are recorded in Appendix B and the body of this document); there are no outstanding items:

  • [x] Whether Internal pub should be tightened → Decision: tighten it in Phase 2 according to reachability in the intra-package use graph, with validation against a Bin-role corpus as a prerequisite (see Phase 2 of the implementation strategy)
  • [x] Explicit [[test]] declarations → Decision: do not introduce them; the Test role is classified only by the 036 rules. If 036 later requires explicit declarations, it will extend them itself
  • [x] A workspace root overriding member export surfaces → Decision: not allowed. Member self-containment is a core 014c design principle, and root-level overrides would break encapsulation

Appendix B: Design Decision Record ​

DecisionResolutionDateRecorderBasis
Number029f (029b was reserved for hot reload, 029c was deleted, and 029d/029e are occupied)2026-09-12Chen XuRFC-029 §Sub-RFC Planning
Belongs to the 029 family rather than being a top-level RFCYes2026-09-12Chen XuImport surfaces, reachability, and entry points all belong to module-graph semantics; 029 already consumes the [[bin]] entry-point priority
Visibility keywordNot introduced2026-09-12Chen XuMirrors RFC-029's "visibility does not exist" decision; import surfaces are carried by distribution boundaries
Status of #321 Decision BDowngraded to "transitional semantics when no target exists"2026-09-12Chen XuReporting pub for the Bin role implements #321 Option A
Role granularityFile-level2026-09-12Chen Xu015 field granularity ([lib] single file, [[bin]] list, [exports] mapping)
[binaries] disambiguation014b precompiled distribution artifacts ≠ [[bin]] source roles2026-09-12Chen XuTwo conceptual layers (download policy vs. compilation role), fixed before 014c is implemented
Internal pub tighteningTighten in Phase 2 according to intra-package use-graph reachability; prerequisite = Bin-role corpus validation2026-09-13Chen XuGradual tightening in the under-reporting direction; corpus-driven validation avoids premature false positives
Explicit [[test]] declarationNot introduced; Test is classified only by 036 rules2026-09-13Chen XuDo not add a configuration surface before 036 needs one
Workspace root overriding member export surfacesNot allowed2026-09-13Chen XuMember self-containment is a core 014c principle, and root-level overrides would break encapsulation
Whether main is called automatically under ScriptNo automatic call—top-level statements are the program; main() must be explicit2026-09-17Chen XuAllowing both rules to coexist would cause an explicit main() to run twice (#356); Script can have only one execution entry point
Whether the role model is used for entry-point determinationYes (previously it was used only for dead-code warnings)2026-09-17Chen XuThis RFC defines the Bin rule that "main is a reachability root"; without connecting it to entry-point determination, that semantic would have no effect

Appendix C: Glossary ​

TermDefinition
RoleThe compilation-target identity of a source file: Script / Bin / Lib / Test / Internal
Import SurfaceThe set of files that are legal starting points for cross-package use resolution, declared or inferred through [exports]/[lib]
Distribution Boundary029 terminology: the package's externally exposed scope; this RFC refines it from the implicit form (all pub files) into the import surface
Script ModeThe bypass form for directly executing a single file without a manifest; all behavior remains as-is

References ​

  • RFC-029 Module Semantics (parent RFC: entry-point selection, visibility decisions, sub-RFC planning)
  • RFC-015 Configuration System ([lib]/[[bin]]/[exports]` field definitions)
  • RFC-014b Build System and Binary Distribution ([binaries], the terminology-disambiguation target)
  • RFC-014c Workspace Support (the first consumer of the import surface, under review)
  • RFC-036 Test Framework (source of the Test-role rules)
  • #321 M2 Independent Warning-Code Delivery Channel (origin of Decision B and Option A)

Known Defects: Resolved (2026-10-16, Round 1) ​

The previous version (2026-10-09) listed the following three items as "three design defects in the reference pool." All three were implemented in Round 1 (commit 3863a9ff0); with the P4 4.2.9 split, collect_project_refs and orchestrator.rs were moved into src/driver/{state,arms,helpers}.rs. All file:line references below were retaken at the referenced revision.

Three Design Defects in the Reference Pool — Correction Status ​

#Original defectCurrent state (2026-10-16)Implementation (rev 3863a9ff0)
1The scanned surface was a directory rather than the compilation surfaceThe pool's roots are package targets: collect_package_refs (helpers.rs:481) uses the [[bin]]/[lib]/[exports]/[run].main roots from roles::ExplicitSurfaces to call discover_with_used for the compilation set; it does not scan the directory for entry points. When every root fails, it falls back to the compilation set of the file being checked itself (collect_compilation_refs / helpers.rs:454)src/driver/helpers.rs:454-512 (fallback path); src/driver/helpers.rs:481-512 (manifest-declared-surface path)
2The granularity was project-level bare names, with no module dimensionThe pool type is HashMap<String, HashSet<String>>: the key is a module key, and the value is the set of reference names in that module. At the consumer, arms.rs:603-609 unions all module entries except those of the current unit and passes them to DeadCodeAnalyzer; a module's own names (top-level definitions and local bindings, except imported use names) no longer exempt same-named definitions in other modulessrc/driver/arms.rs:603-609 (consumer-side other_module_refs); the sole assembly entry point is src/driver/helpers.rs:429-449 (collect_ref_pool)
3Script reused the Lib pool, violating single-file semanticsScript does not connect to the pool: the match us.role in arms.rs:611-623 assembles only Bin/Internal (set_exempt_pub) and Lib (set_cross_file_refs); Script/Test take the _ => {} default arm, and these paths determine dead code only from the file-local definition-use graphsrc/driver/arms.rs:611-623

Subsequent improvements 4 / 5 — Correction Status (2026-10-16, Round 2)

These two items were originally listed as "pending P4 4.9." Both were implemented in Round 2 (commit e6cf1aeaa, pushed on 2026-10-17). The file:line references below were retaken at revision e9675c9dd (2026-10-17 Round 3 closure note—the fix round and closure round modified the same anchor files, so the line numbers were retaken; the Round 1 lesson was that a local hash before push can be rewritten by pull --rebase).

#Original improvementCurrent state (2026-10-16)Implementation
4Refine the consumption definition: distinguish "imported" from "actually used after import" (only the latter counts as consumption)The consumption criterion is "actually used after import": a consumption record means that a module uses use to bring name n from module M into scope and actually references n at the use site, and is recorded only against M (RefPool::consumed_from). Merely appearing in a use item (with no use site), or another module referencing an identifier with the same name, does not count as consumption. The target module of an import is determined by the module-key set from the discovery phase (resolve_import_module, without introducing a separate path-resolution mechanism—it reuses the discovery-phase resolution artifacts delivered in 4.6.1; see 39546020). Namespace forms (use lib + lib.foo()) are attributed in the same waysrc/driver/helpers.rs:442-447 (RefPool); src/driver/helpers.rs:449-506 + :511-524 (collect_ref_pool + resolve_import_module); src/frontend/core/typecheck/passes/dead_code.rs:186-200 (ModuleNames), :384 (collect_module_names), :132-184 (ImportFace / collect_import_face)
5Separate the test pool: references from tests/ must not exempt production code (src/)FileRole::Test does not contribute to the consumption surface: Test-module references are placed in a separate pool (Test itself does not participate in dead-code determination, so its references do not spill over), and production-code definitions are kept alive only by consumption from production code. Roles are classified at a single point by roles::classify (RFC-036 test-discovery rules)src/driver/helpers.rs:463-466 (Test short-circuit in collect_ref_pool); src/driver/helpers.rs:707-708 (roles::classify as the single classification point); src/driver/arms.rs:633-635 (Test skip shared by the fallback and declared-surface paths); role feeding into the pool at :661-672

Residual surface (registered, non-blocking): ① Field/method member accesses (obj.render has only a short name) cannot be attributed to the receiver type's module at the AST layer—when a base name matches a namespace import, it is attributed through the import, while module-qualified construction ns.T is classified under the type-name surface for method attribution (see §4.9.7 below); all other names are conservatively included in RefPool::field_names (collect_ref_pool in src/driver/helpers.rs). ② Method reachability: PlanId-keyed resolution artifacts narrow candidates one by one and by definition unit (resolved_method_marks)—sibling overloads in the same unit that are not matched are truthfully reported as W1005; cross-unit, same-name, same-order uncalled definitions are likewise truthfully reported under reachable forms (issue #464, closed; see the mechanism and measurements below). Residual boundaries (registered; do not claim full coverage; all are based on measurements): (a) A standalone check <definition file> (the file has no call sites, and its callers are not in the unit set) ⇒ no resolution entry ⇒ fallback to the pool's name-level exemption (RefPool::field_names is globally flattened) ⇒ not reported; (b) The same bare type name is brought into scope by multiple modules (the source program is already ambiguous at the name level, and the entry point separately reports E5006) ⇒ the entire candidate surface is skipped ⇒ no resolution entry ⇒ same-name, same-order groups are not reported; (c) A caller in this unit has made any method call on a type name from another unit (even if it does not match that definition) ⇒ that definition is merged by possible ownership (typed_owners rule ②) ⇒ not reported; when both sides merely construct values and make no method calls, typed_owners does not apply, and both sides are truthfully reported as W1005 (t20 fixture: both sides only construct ⇒ 2 W1005 diagnostics); (d) A whole-module import use M does not bring a bare type name into scope, and the std module's candidate surface is not connected—neither form produces an entry and both fall back to name-level exemption. Fallback boundary: when a name group has no resolution record in the unit (for example, call-site ambiguity E1107 or a call form that does not go through resolution), it falls back to a collective short-name decision (in the under-reporting direction)—therefore, do not claim that "every uncalled method is truthfully reported."

Reference-Count Distortion (issue #450) — Correction Status (2026-10-16) ​

Original registration: an overloaded method could still be falsely reported as W1005 Unused method even though it was called and resolution took effect (the reference count was distorted for overloaded calls). On 2026-10-16, the user's Decision A registered this as an independent level-three task and merged it into Round 2. This item is Category D (deleting a false positive changes the diagnostic's external surface), and implementation was authorized.

StageOriginal defectCurrent stateImplementation
Reachability probeThe scan looked up references by qualified name (Point.render), while reference collection captured only the short name (obj.render() contains only render) ⇒ called methods were always unreachable, and W1005 was falsely reported when no project root path existedMethods are probed by short name, and then narrowed candidate by candidate using PlanId-keyed resolution artifacts (resolved_methods + resolved_groups; sibling overloads not matched by a resolution are still reported as W1005). Scope boundary: within the same unit, this applies candidate by candidate; for cross-unit (registry-resolved) calls, after the producer side (b8b3cc3f6) and driver-side attribution (this batch) are implemented, it likewise applies candidate by candidate and by definition unit under reachable forms (see residual surface ② and §4.9.7 below)src/frontend/core/typecheck/passes/dead_code.rs:782-792 (probe); :815-877 (candidate-by-candidate determination and exemption gate)
Definition-table keyingall_defs was keyed by qualified name ⇒ same-named overloads overwrote each other (only one of the two remained, so only one W1005 was reported)The definition table contains one entry per definition: methods are appended, while same-named non-method bindings are deduplicated by name, retaining the last one (overloads are independent definitions, whereas top-level reassignment is the same binding)src/frontend/core/typecheck/passes/dead_code.rs:304-322 (record_definition), :28-29 (fields)

Reason not to change this in P3.5 (unchanged from the previous version): module-level resolution requires use-item path resolution to be complete (use a::foo → foo comes from module a). This belongs to the P4 stage contract and the unified Driver.

Cross-Unit Method Reachability Attribution (issue #464) — Correction Status (2026-10-17) ​

Original registration (residual surface ②): method calls across units (resolved through the registry) did not produce PlanId-keyed resolution entries ⇒ the name group fell back to the pool's name-level exemption ⇒ uncalled methods with the same name and order across units were not reported. This item was implemented in two parts: the producer side (cross-unit method calls produce resolution entries, commit b8b3cc3f6; its injection surface was pair-filtered by name attribution during the fix round, as shown in the table below) and the driver-side attribution (provide reachability marks by definition unit and disable name-level exemption). The file:line references below were taken from the driver-side attribution working tree—commit d5c00235a; the producer-side commit was b8b3cc3f6 (see above). All file:line references in this section were retaken at revision e9675c9dd during the 2026-10-17 Round 3 closure, covering the shifted injection-surface range after d5c00235a was implemented by the fix round d5dd1a37b. Commit IDs are always taken as post-push truth (a local hash before push may be rewritten by pull --rebase; see.

StageOriginal defectCurrent stateImplementation
Resolution-entry productionAll three candidate tables for a cross-unit call site were missing (method_overloads / method_overload_ir_names / method_overload_param_names) ⇒ the entire resolution section was skipped ⇒ 0 entriesCandidate groups—“candidate / mixed IR name / declaration-order parameter names”—are packaged in matching order and passed across units through ModuleInfo.method_overloads; the Registry merges them deterministically by ascending module key. The Typecheck arm takes candidates pair by pair according to the current unit's import face—it injects only candidate groups for which “the module providing the key == the module providing this type-name prefix in the current unit's scope” (name ← module pairing, with no cross-pair combinations; an owned key slot is not merged externally, and a same-name conflict skips the entire name) ⇒ at that point cands=1, with 1 entry (Temp.to). Fix-round measurement (F1): previously, the “name set × module set” combination merged same-named type candidates from another module into the same key slot ⇒ use a.{Temp} + use b.{Other} (a also defines Other, b also defines Temp, and the method has the same name and order) caused check to report 2×E1107 and exit 1 (a program that previously succeeded failed to compile); after pair-by-pair filtering, check/run both exit 0, and the fixture is stored under tests/yaoxiang-multifile/ref-pool-cross-unit-name-owner/. Injection-surface fix round (F1, d5dd1a37b): before the fix, the “name set × module set” combination merged same-named type candidates from another module into the same key slot ⇒ use a.{Temp} + use b.{Other} (a also defines Other, b also defines Temp, and the method has the same name and order) caused check to report 2×E1107 and exit 1 (a program that previously succeeded failed to compile); after pair-by-pair filtering, check/run both exit 0—the fixture is stored under tests/yaoxiang-multifile/ref-pool-cross-unit-name-owner/, and the pinned test is src/driver/tests/overload_injection.rs (placed by commit c2f887843)src/frontend/core/typecheck/environment.rs:145 (merge_from: matching-order append at candidate-group granularity), :336 (snapshot), :384 (injection), :399 (append_overload_group: the sole insertion point for the three parallel tables, with an equal-length debug assertion before insertion); src/frontend/module/registry.rs:150 (merge_method_overloads); src/frontend/module/mod.rs:155-157 (ModuleInfo fields); src/driver/arms.rs:344-358 (injection surface), :1521-1579 (visible_method_overloads, the sole injection point: name ← provider module pair-by-pair, same-name conflicts skip the entire name, and owned key slots are not merged externally). Injection-surface fix round (F1, d5dd1a37b): before the fix, the “name set × module set” combination merged same-named type candidates from another module into the same key slot ⇒ use a.{Temp} + use b.{Other} (a also defines Other, b also defines Temp, and the method has the same name and order) caused check to report 2×E1107 and exit 1 (a program that previously succeeded failed to compile); after pair-by-pair filtering, check/run both exit 0—the fixture is stored under tests/yaoxiang-multifile/ref-pool-cross-unit-name-owner/, and the pinned test is src/driver/tests/overload_injection.rs (placed by commit c2f887843)
Driver-side attributionResolution entries were globally marked by name (one set of (base name, declaration order)) ⇒ another unit's same-name, same-order definition was exempted by a call to its same-named sibling (cross-unit, same-name, same-order definitions were previously not reported)Marks are attributed by definition unit (MethodMarks { by_unit, groups }): for an entry named {Type}.{method}#k, {Type} is the definition-side bare name and carries no unit ⇒ the recording unit's type-name surface is used to compute the set of modules from which that unit can construct the name, and the entry is assigned to each unit in that set; groups contains the name groups for which entries have appeared (globally)src/driver/helpers.rs:569-573 (MethodMarks), :591-619 (typed_owners: brace-form items + inline alias targets + module-qualified access ns.T, reusing collect_module_names + resolve_import_module as the single implementation point), :621-654 (resolved_method_marks, a pure read through OverloadResolutions::iter), src/driver/arms.rs:650-658 (per-unit by_unit[unit_key]), :649-660 (analyzer injection)
Decision surfaceName groups with resolution records still used the pool's name-level exemption (globally flattened short names)Name groups with resolution records do not use name-level exemption: live declarations in the current unit are accepted, while unmatched definitions are truthfully reported as W1005 (!marked_group is the precondition for the exemption gate)src/frontend/core/typecheck/passes/dead_code.rs:44 (field), :252-257 (set_resolved_groups), :262-267 (method_group_has_marks), :782-795 (candidate-by-candidate reachability), :815-877 (per-definition determination / exemption gate / W1005 emission)

Externally observable changes (Category A: old behavior was unsuccessful ⇒ fix opportunistically, and register the same commit):

  • Cross-unit overload resolution previously did not take effect: all three candidate tables were missing ⇒ fallback to the cross-unit single-value binding table (method_bindings, last-one-wins) ⇒ calls to same-named methods with multiple candidates reported error[E1002] (measured: Expected type 'string', found type 'int64'); after the fix, candidates are resolved according to the argument types, and the same fixture measures Type check passed. The criterion is the integration case test_multifile_cross_unit_method_overload_resolves_by_argument_type (tests/integration/multifile.rs, with same-named, same-order Int/String candidates and two calls each matching one)—turning off the injection surface makes this case fail with the same E1002.
  • Cross-unit, same-name, same-order uncalled methods now begin to be truthfully reported as W1005: a three-folder fixture (main.yx imports the named type with use a.{Temp}, while use b only brings b into the compilation set) was measured—a.Temp.to has a call site and is not reported, a.Temp.other is reported, and b.Temp.to is reported; before the fix, the same fixture reported only a.Temp.other (the definition in b escaped through the pool's name-level exemption). The stored fixture is tests/yaoxiang-multifile/ref-pool-cross-unit-method/ (reproducible through the CLI); the driver-level pinned test is src/driver/tests/method_unused.rstest_cross_unit_uncalled_same_named_method_is_reported.

Residual boundaries (registered; do not claim full coverage; each is based on measurements):

  1. Standalone check <definition file> (the file has no call sites, and its callers are not in the unit set) ⇒ no resolution entry ⇒ fallback to name-level exemption ⇒ not reported (in the under-reporting direction). Measured: with the same three-folder fixture, check b.yx reports only an unused type W1002 and does not report b.Temp.to.
  2. Ambiguity at the name level: the same bare type name is brought into scope by multiple modules (use a.{Temp} + use b.{Temp}) ⇒ the entire candidate surface is skipped ⇒ no resolution entry ⇒ same-name, same-order groups fall back to name-level exemption and are not reported; this entry point separately reports E5006 Duplicate import. In the measured control case (importing only b as a namespace), sibling candidates are truthfully reported, demonstrating that the criterion is not inert.
  3. The caller in this unit has made any method call on another unit's type name (even if it does not match that definition) ⇒ that definition is merged by possible ownership (typed_owners rule ②) ⇒ not reported; when both sides merely construct values and make no method calls, typed_owners does not apply, and both sides are truthfully reported as W1005 (measured fixture t20-b3-no-method-call: both sides only construct ⇒ 2 W1005 diagnostics)—in the under-reporting direction.
  4. Inline aliases use M.{T as X} and module-qualified construction ns.T do not inject the candidate surface (producer-side narrowing rule ②): the call-site key remains the definition-side T (measured: both X(..).to() and ns.T(..).to() use the key T.to) ⇒ cross-unit exactness for a same-named type's #k remains bounded by “the set of modules from which the recording unit can construct the name” (as in residual boundary ④ above); precisely for this reason, these forms cannot classify another unit's same-name, same-order definition as dead (otherwise a genuinely called method would be falsely reported).
  5. A whole-module import use M does not bring a bare type name into scope (measured: writing Temp(...) reports E1001), and the std module's candidate surface is not connected (its ModuleInfo is constructed through the std registration path)—neither form produces an entry and both fall back to name-level exemption.

The driver-side read is a pure read: resolved_method_marks goes through OverloadResolutions::iter (it does not touch get and is not counted in the consumption ledger) ⇒ it does not mask W1090's "consumption must reach" settlement; the driver-level pinned test is test_resolved_method_marks_read_leaves_consumption_ledger_untouched (after the read, the entry remains in the unconsumed() difference).

Closure measurement addendum (2026-10-17 Round 3; after the injection-surface fix round d5dd1a37b and the pinned-test placement c2f887843): Injection-surface filtering takes candidates pair by pair according to “name ← provider module” (merging only candidate groups for which “the module providing the key == the module providing this type-name prefix in the current unit's scope”)—the sole implementation point is visible_method_overloads (src/driver/arms.rs:1521-1579, production call site src/driver/arms.rs:354); there is only one downstream insertion point (environment.rs:399 append_overload_group: the three parallel tables are appended in matching order + an equal-length debug assertion; appending between groups goes only through merge_from, environment.rs:145). Mutation verification: restoring cross-pair filtering makes the driver-level pinned tests fail with 2×E1107/2×E1053, while all three assertions in the primary acceptance fixture remain unchanged (demonstrating that the fix does not regress the primary acceptance). Independent validation/re-review used a pair of frozen revisions (before the fix d5c00235a / after the fix e9675c9dd) and compared two binaries: the primary acceptance fixture tests/yaoxiang-multifile/ref-pool-cross-unit-method/ produced the same diagnostics on both sides; negative controls (no same-named type / same-named type but a different method name) were green on both sides; the existing ambiguity behavior for the same bare type name brought into scope by multiple modules was consistent on both sides; and the reverse false-negative surface is covered by truthful W1005 reporting for same-name, same-order uncalled definitions (the fix no longer swallows them).

Criteria and drift (measurements for this batch, including the closure round): driver-level pinned tests—5 for attribution (primary acceptance / inline-alias false-positive guard / module-qualified-name false-positive guard / bidirectional key scope / pure read, src/driver/tests/method_unused.rs) + 3 for injection-surface filtering (pairwise name-ownership filtering / no false positive when method names differ / equal-length three-table pairing, src/driver/tests/overload_injection.rs, placed by commit c2f887843), plus 4 old #450 criteria with no regression; 204 IR snapshots with zero drift; the corpus baseline grew from 346 → 347 lines (driver-side attribution round, new fixture ref-pool-cross-unit-method/) → 348 lines (injection-surface fix round, new fixture ref-pool-cross-unit-name-owner/), with each round adding exactly one behavior record and all existing rows remaining byte-for-byte unchanged (the baseline tests/baselines/corpus-parity.jsonl has 348 lines at e9675c9dd).

Cross-Unit Same-Named Type Method Dispatch Attribution (issue #465) — Correction Status (2026-10-25) ​

Symptom: two compilation units each define a same-named type Temp and a same-named method Temp.tag (the implementations can be distinguished: a = v + 1.0, b = v * 10.0). The entry point imports a by bare name (use a.{Temp}), then imports b using an inline alias (use b.{Temp as TempB}) or module-qualified construction (b.Temp(..)). Both constructions are correct (the field values are correct), but u.tag() dispatches to a's implementation; run exits 1 (assertion failure)—a silently incorrect value (semantic-correction triage Category C). The check warning surface depends on whether the manifest can be read: the manifest form given in the issue ([package] contains only name and lacks version) actually produces 2 W1002 unused type diagnostics (a.yx:1:1 / b.yx:1:1); adding version produces 0 warnings. Manifest parse failure / missing required fields silently degrades (residual boundary 4), which is unrelated to the dead-code criterion itself.

StageOriginal defectCurrent stateImplementation
Dispatch-name sourceThe dispatch name was the definition-side bare type name plus the method name (Temp.tag). In typecheck, MonoType retains only the definition-side bare name (Temp) for imported types, so same-named types in different units are indistinguishable at the type layerThe dispatch name is first attributed to the definition unit by the receiver's written type name: Temp.tag → b.Temp.tag (written name → import surface → definition-unit qualified name). Method calls and operator interfaces (Index / Equal) use the same criterionsrc/middle/core/ir_gen.rs:1265 (method_dispatch_name, the sole criterion), :1232 (imported_type_owner: use_aliases + Resolver::resolve_namespace + the Registry's single source of truth, ExportKind::Type; an exact authoritative qualified-name match returns immediately and is not resolved again), :1188 (constructor_written_type_name, pure syntactic extraction), :1169 (written_type_name_of, annotation written name)
Written-name recordingThis concept did not exist: ir_gen derived dispatch solely from the bare name in MonoTypeLocal variables are recorded in symbol-table entries (SymbolEntry.written_type, whose scope follows the symbol table); top-level bindings are recorded in a per-unit table (global_written_types; in Script form, t = Temp(1.0) is a global slot); parameter annotations are recorded in the same chainsrc/middle/core/ir_gen.rs:1115 (note_local_written_type), :1129 (note_param_written_types), :1159 (binding_written_type: local first, then top level), :109 (SymbolEntry.written_type field), :3255 (top-level registration point)
Five production pathsThe three method-naming paths (RFC-004 binding / PlanId-keyed overload resolution / bare-name inference) each produced their own names; the two operator-interface arms (Index → Type.index, Equal → Type.equal) separately composed short type names, completely bypassing attribution (fix-round R1 measurement)All five paths use method_dispatch_name to produce the final call name (one criterion only, D3)src/middle/core/ir_gen.rs:8318 (binding arm), :8379 (resolution arm), :8532 (bare-name arm), :6444 (Index arm), :7858 (shared binary-interface arm: Equal + Add/Subtract/Multiply/Divide/Modulo)

Mechanism discrimination (discriminating experiment, performed before the fix): issue #465 listed two candidate mechanisms—(a) type_bindings was keyed by short type name, causing same-named units to overwrite each other; (b) PlanId-keyed resolution overrode binding.function. Only (b) applied to this form: the entry unit's type_bindings was empty (the type body contained no inline external binding), both method calls matched overload_resolutions, and both resolution names were the definition-side bare name Temp.tag; qualify_names then resolved the bare prefix Temp to the bare-name provider a (use a.{Temp}), so both call sites landed at a.Temp.tag—consistent with the issue's 8 control cases (winner = bare-name owner; independent of import order and of whether an a-side call site exists; correct when the two units' type names differ or when two types are in the same file). Mechanism (a) was inactive in this form (seed_cross_file_types records only the short names of bindings inline within a type body, and is unrelated to the method-statement form).

Externally observable change (Category C: old behavior was unsuccessful ⇒ fix opportunistically): a program that previously produced a silently incorrect value now executes the implementation from each unit's own definition; cross-unit method calls with no same-named type and the two negative controls (different type names / two types in the same file) remain unchanged. The criteria are entirely value-level: after changing the two units' method bodies to be distinguishable (+1.0 / *10.0), the assertions produce 2.0 / 20.0—before the fix, the same fixture produced 2.0 / 3.0 (CROSS_UNIT_A/B previously had identical implementations in both units and was therefore blind to the defect).

Criteria and drift (measurements for this batch, including the fix round): 10 driver-level pinned tests (inline alias / module-qualified construction / both operator arms / local-type control / 5 of the 8 control cases / negative controls, src/driver/tests/method_dispatch.rs; the structural layer reads the merged IR call name, and the behavioral layer reads the interpreter's global slot value) + 5 integration value-level assertions (tests/integration/multifile.rs, including the R1 operator form and the R2 p.q + alias forms); mutation verification: turning off method_dispatch_name attribution (returning the original definition-side name) ⇒ the two new same-named-type cases fail (the call names revert to a.Temp.tag ×2), while the negative controls and the existing 159 driver-level cases do not regress; the patch is mechanically reversible (git apply -R produces a byte-for-byte match with the mutated file). The corpus baseline tests/baselines/corpus-parity.jsonl has 356 lines with zero drift, and the 216 IR snapshots have zero drift (this change only affects call-name attribution; it does not change the IR shape or add any diagnostic code / warning).

Fix rounds (R1–R4, 2026-10-25; source = needs_revision from an independent-family review of the frozen baseline):

  • R1, the two operator-interface arms: Index / Equal dispatch previously used the short type name supplied by typecheck to compose the call name (Temp.index / Temp.equal), without attribution ⇒ operator implementations for same-named types in different units landed in the wrong unit. Measured on the frozen baseline: u[0] produced 3.0, and u == t produced true (should be 20.0 / false), while check exited 0. Both arms now use method_dispatch_name (:6444 / :7858), producing 20.0 / false after the fix; both local-type forms remain byte-for-byte unchanged (pinned test_local_type_operator_arms_keep_own_dispatch + corpus operator_index.yx / struct_equality.yx, all green). Review measurement: :7858 is the shared arm for all “interface-driven binary operations” (Equal + Add/Subtract/Multiply/Divide/Modulo)—for a same-named type in two units, u + u produced 3.0 before the fix and 20.0 after it, and all five arithmetic families were corrected by the same criterion. The original table in this section described it as the “Equal arm,” which underestimated its coverage; it has been corrected accordingly.
  • R2, single attribution criterion + no second resolution: the previous constructor_written_type_name produced an authoritative qualified name (p.q.Temp), and imported_type_owner then passed it through resolve_namespace again. The first segment was rewritten by the namespace alias table (use other as p ⇒ other.q.Temp) ⇒ the type-export determination failed ⇒ fallback to the bare name (measured: y = 3.0). The constructor now performs only pure syntactic extraction (the written name is preserved verbatim), imported_type_owner is the sole determination point, and an exact authoritative qualified-name match returns immediately without being resolved again (:1232). Pinned: test_multifile_qualified_module_key_not_rewritten_by_namespace_alias (module key p.q + an unused use other as p; red before the fix, green afterward).
  • R3, documentation correction: this section's original statement that "check [reports] 0 error / 0 warning" did not match the measurements—when the issue's manifest lacks version, check reports 2 W1002 diagnostics. It has been rewritten to match reality and registered as residual boundary 4; the silent degradation of manifest parse failure / missing fields is itself another defect (not fixed in this batch).
  • R4, pinned coverage for the 8 control cases: the driver added 5 value-level cases—reversing use order, reversing the two units' method bodies (the values follow their units: 10.0 / 3.0), changing the bare-name owner to the lexicographically later z.yx (demonstrating that the winner comes from the use surface rather than ordering), calling only the alias side, and using a same-file two-type negative control; together with the original 3 cases, all 8 control cases are now stored and rerunnable.
  • Mutation verification (mechanically reversible; git apply -R produces a byte-for-byte match): M1 disables method_dispatch_name attribution ⇒ 7 cross-unit cases fail (including the two operator arms and 4 control cases), while the 3 local/negative cases remain green; M3 restores the “old constructor + removal of exact matching” ⇒ R2 fails.

Residual boundaries (registered; do not guess):

  1. Fallback to the bare name when the written name is unavailable (unchanged from before the fix): a receiver that flows into the expression through a function return value, field, or container element has no written name on which to rely—for example, after u = make_b() (a cross-unit function returning b's unit type), u.tag() still resolves through the bare-name prefix.
  2. Inline alias × same-named overload: typecheck's candidate-injection surface remains narrowed by the §4.9.7 rule ② (inline alias / module-qualified forms do not inject), while dispatch only replaces the type prefix and preserves the resolution's #k mixed order—the cross-unit exactness of #k is unchanged (the same as §4.9.7 residual boundary ④).
  3. Cross-unit value-binding handoff: an instance introduced by use M.{v} (whose type is recorded by the defining unit) has no local written name and likewise falls back to the bare name.
  4. Silent degradation when manifest parsing fails / required fields are missing (measured): when [package] lacks version (the manifest form given in issue #465), check reports 2 W1002 unused type diagnostics (a.yx:1:1 / b.yx:1:1)—both types are referenced by the entry point, so these are false positives; adding version produces 0 diagnostics, and an invalid TOML manifest degrades in the same way. The root cause is the silent-degradation path for manifest parse failure, not the dead-code criterion itself (registered as a separate issue; not fixed in this batch).