Skip to content

One table-driven enclosing-scope and in-file test-scope walker instead of per-language copies #356

Open

Description

@joyful-ii-V-I

Part of the language-architecture cleanup tracked in #354 ("common stays common").

Problem. The same idea is written once per language in src/ingest_names.h:

  • enclosing scope: rustEnclosingScopeOf and kotlinEnclosingScopeOf are near-copies of the generic enclosingScopeOf (0.82 similar by ripwire --clones);
  • in-file test scope: four parallel *InFileTestScope functions (C#, JS, Python, Rust).

Change. One table-driven walker for each: a small constexpr per-language table (node kinds that open a scope, how the scope name is read, which nodes mark a test scope) and one function that reads it. The style rule is CONTRIBUTING §3, "Declarative constexpr tables over scattered switch/if".

Acceptance. Output byte-identical on every language (existing gates + a before/after map); ripwire --clones no longer reports the group; no new per-language functions.

Size: about a day. A good way to learn the ingest pipeline. Comment here to claim it.

Activity

  1. gounthar commented on Oct 16, 2026

    @gounthar

    I'd like to take the enclosing-scope half of this (9a). The in-file test-scope half stays open for someone else.

    I have it working locally. Kotlin's walker becomes one row in a small constexpr table ({Lang, owner kinds, name kind}), read by one positional walk. The definition pass looks its language up in the table instead of testing le.lang == Lang::Kotlin, so kotlinEnclosingScopeOf goes away and the ratchet in test/langidentity/ratchet.tsv drops from 352 to 351.

    What I ran:

    • langidentitycheck.sh, main 1bcb6540 against the branch, on the Kotlin fixtures plus square/okio, with ripwire's own src/ as a C++ control: 114 argv, all SAME
    • kotlincheck.sh: passes
    • --clones on src/: both 0.82 pairs with kotlinEnclosingScopeOf are gone, and the new walk is in no other group

    I left rustEnclosingScopeOf and the generic enclosingScopeOf as they are. Rust reads type:/name: fields, has the includeModules mode for Self:: and cleans up the path text, so I don't think a positional row fits it. And once the Kotlin copy is gone, --clones doesn't pair it with the generic walker anymore. Is that fine with you, or do you want both in the same table anyway? I can try it if you prefer, I'm just not sure it would make the code smaller.

    The reason I started here: the OCaml definitions PR for #377 needs the same walk for module scopes, and with this in, OCaml is a second row instead of a new branch.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions